none
Why command line args doesn't passes to my application? RRS feed

  • Question

  • Hi,

    I want my form application can be launched or say activated by a local file, for example an RTF file. However, it doens't open any file when I double clicked on an associated file. It just invokes my app with initial form.

    Then I went into the code and added following codes to check if the commandline parameters are passed well, but each Msgbox tells me "".

    Msgbox(My.Application.CommandLineArgs.Item(0))
    Msgbox(System.Environment.GetCommandLineArgs(1))

    However, if I try with my application that is found under my ...\bin\Release\app.exe, the commandline params are then successfully passed. So it seems that the problem only happens on client enviornment (is it?).

    I've checked the MSDN Library it says for Click-Once applications should use ApplicationDeployment.ActivationUri. But pity is that when I try it in code, I could find no member in My.Application.Deployment, so what's next?

    I must missed something so anyone may help would be appreciated. Anyway, how do I turn off Click-Once since it automatically turns on after each publish?

    Thanks a lot.

    Monday, December 31, 2012 1:50 PM

Answers

All replies

  • Your code is correct as to how to get the information. 
    I think the problem is that you are trying to debug the application in Visual Studio and it goes to the initial form. 
    Visual Studio has an area where you can debug with arguments... Go to Project > ProjectName Properties > Debug  and you will see a box where you can enter the commandlineargs manually for debugging purposes.

    My status

    Monday, December 31, 2012 2:11 PM
  • The debug runs fine (opens the RTF file in the args).

    The application in the ...bin\Release\app.exe also runs okay with drag-dropped files (also opens the drag-dropped RTF file).

    But only when I publish, ran Setup.exe, and double click any RTF file or drag-drop one onto the .exe icon, the application launches but doesn't read the RTF file -- the command line arg is "".

    So what's the reason?

    Monday, December 31, 2012 2:23 PM
  • If you could upload a copy of what you are working with I could assist you further.

    My status

    Monday, December 31, 2012 2:27 PM
  • Victor,

    Kindly that you tell us what is working, is there something which is not working because as far as I can understand what you wrote you did not describe that. 

    By the way, most of us know it is working what you wrote.


    Success
    Cor

    Monday, December 31, 2012 2:45 PM
  • You need to confirm that the command line is being correctly created for your application. Open Registry Editor and look at
        HKEY_CLASSES_ROOT\.ext

    for the (Default) value for the filename extension that you has been associated with your application to get the class name.

    Now look in

      HKEY_CLASSES_ROOT\class\shell\open\command
    

    at the (Default) value. That's the command line which will be used when your application is started by double clicking in Explorer.  That must include the %1 replaceable argument, which is where Explorer will place the file name of the file that was selected.

    Monday, December 31, 2012 9:04 PM
  • Acamar,

    I've followed your instructions and the registry does contain %1, full value:

    rundll32.exe dfshim.dll, ShOpenVerbExtension {55b4eaad-3393-45ee-ac2a-2b644baaabde} %1

    I'm wondering why the command line do passes well to the application when in VS Enviornment, and also well from the bin\Release\app.exe, but failed only after deployment and install. Anyway, what is Click-Once? Why must it reset to use Click-Once secure settings after each publish? I think what was seen in VB6 and other kdes are as simple as always applicable...

    Tuesday, January 1, 2013 6:15 AM
  • Cor,

    My app works all fine, it should open RTF file and load all text into a RichTextBox.

    The only problem is the start-up command line function. It seems that this is the first time who's posting a question like this? I'm not sure if I'm the first people that met it but the problem really occurs.

    Any idea please?

    V.

    Tuesday, January 1, 2013 6:27 AM
  • That command line is for rundll32. 

    In debug mode the command line is manufactured by the IDE, and drag and drop isn't relevant to your problem. So it seems that the file association was never properly created.  You need to associate the file type with your application, using a command line that invokes the application and passes the filename.

       MyApplication %1

    Tuesday, January 1, 2013 6:27 AM
  • Try this...

    Dim regKey As RegistryKey
                regKey = Registry.ClassesRoot.OpenSubKey("*\Shell\YourApp.Open", True)
                regKey.SetValue("", "Open with my app")
                regKey.Close()
    
                regKey = Registry.ClassesRoot.OpenSubKey("*\Shell\YourApp.Open\Command", True)
                regKey.SetValue("", System.Reflection.Assembly.GetExecutingAssembly.Location() & " %1")
                regKey.Close()
    also add this to imports section...
    Imports Microsoft.Win32



    My statusDim Blondedude092 as SkypeUser


    • Edited by Dmitry Post Tuesday, January 1, 2013 6:43 AM
    Tuesday, January 1, 2013 6:41 AM
  • Sorry that code won't work but this is the correct one...

    Dim regKey As RegistryKey
            regKey = Registry.ClassesRoot.CreateSubKey("*\Shell\YourApp.Open")
    
            regKey = Registry.ClassesRoot.OpenSubKey("*\Shell\YourApp.Open", True)
            regKey.SetValue("", "Open with my app")
            regKey.Close()
    
            regKey = Registry.ClassesRoot.CreateSubKey("*\Shell\YourApp.Open\Command")
    
            regKey = Registry.ClassesRoot.OpenSubKey("*\Shell\YourApp.Open\Command", True)
            regKey.SetValue("", System.Reflection.Assembly.GetExecutingAssembly.Location() & " %1")
            regKey.Close()
    Imports Microsoft.Win32

    This does require administrator  

    My statusDim Blondedude092 as SkypeUser


    • Edited by Dmitry Post Tuesday, January 1, 2013 7:01 AM
    Tuesday, January 1, 2013 7:01 AM
  • Dmitry,

    Thanks for your code that modifies the registry on our own. However, the file association registries that I posted above was totally and automatically generated by .NET when the user install the applicaiton.

    I've attached the msdn page that may explain the problem:

    http://msdn.microsoft.com/en/library/vstudio/microsoft.visualbasic.applicationservices.consoleapplicationbase.commandlineargs(v=vs.100).aspx

    Be notice that it says this:

    In an application that is ClickOnce deployed, use the ActivationUri property of the My.Application.Deployment object to get the command-line arguments. For more information, see Deployment.

    I think this would explain. But my problem still goes to: I can't access any member under Deployment, and I can't find the ActivationUri property.

    Can anyone help?

    • Marked as answer by VictorXP Friday, January 11, 2013 5:14 AM
    Tuesday, January 1, 2013 10:52 AM
  • This occurs in C# as well (VS 2019).

    In VS Debug mode with the command arg passed via the IDE, the app reads the command line argument from System.Environment.GetCommandLineArgs() as arg 1. My code works fine.

    When published however, and a data file is double-clicked, the filename argument is not passed into the program at all. The registry has the correct settings and should read the file.

    This may be a problem with the command string created in the registry:

    rundll32.exe dfshim.dll, ShOpenVerbExtension (guid) %1

    I expect that either rundll32 or ShOpenVerbExtension is not passing the file parameter to the program since neither of them are involved in the VS Debug startup situation.

    I think that this is a bug.


    -Mark

    Sunday, September 8, 2019 4:23 AM
  • This occurs in C# as well (VS 2019).

    In VS Debug mode with the command arg passed via the IDE, the app reads the command line argument from System.Environment.GetCommandLineArgs() as arg 1. My code works fine.

    When published however, and a data file is double-clicked, the filename argument is not passed into the program at all. The registry has the correct settings and should read the file.

    This may be a problem with the command string created in the registry:

    rundll32.exe dfshim.dll, ShOpenVerbExtension (guid) %1

    I expect that either rundll32 or ShOpenVerbExtension is not passing the file parameter to the program since neither of them are involved in the VS Debug startup situation.

    I think that this is a bug.


    -Mark

    Hello Mark, we like to keep relies to the past couple of months and event better within the last 30 days. Something that appears to be a bug should be reported directly within Visual Studio.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, September 11, 2019 1:15 AM
    Moderator