Command Line Args

  • Thread starter Thread starter paul
  • Start date Start date
P

paul

I have a file type that is going to be associated with my
visual basic application and i want the user to be able
to double click on a file of said type and have it launch
the program and load the file. I know there are certain
keys in the registry that i have to create and/or edit.
I have located them, namely HKEY_CLASSES_ROOT\.stdf and
HKEY_CLASSES_ROOT\stdf_auto_file\shell\open\command

The default value for that last key is the path to my
application followed by "%1". I thought that this would
take the file that was double clicked and pass it to my
program but on inspection of the
Environment.GetCommandLineArgs() I found that only the
path to the calling program is getting passed.

Is there a problem with my registry keys or my visual
basic program that needs to be addressed. Any help is
greatly appreciated.
Thanks
-Paul
 
Hello,

You may want to try Microsoft.VisualBasic.Command() function. Here is what
Help file says:

Returns the argument portion of the command line used to launch Visual Basic
or an executable program developed with Visual Basic.

Public Function Command() As String
Remarks
For applications developed with Visual Basic and compiled to an .exe file,
the Command function returns any arguments that appear after the name of the
application on the command line, as in this example:

MyApp cmdlineargs
Example
This example uses the Command function to get the command-line arguments in
a function that returns them in an object containing an array.

Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String = " "
Dim commands As String = Microsoft.VisualBasic.Command()
Dim args() As String = commands.Split(separators.ToCharArray)
Return args
End Function

You may add your own filetypes in setup project configuration.
Hope it helps :-)

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
 
paul said:
I have a file type ... to be able to double click on a file of said
type and have it launch the program and load the file.

Code you application to start with a Sub Main that looks like this:

Sub Main( ByVal saArguments() as String )
' Load and Run() main form in here

With the Registry settings you describe, double-clicking on a file
should fire up your program and deliver [the path and name of]
the file into saArguments( 0 ) - all being well.

HTH,
Phill W.
 
Back
Top