locked
OpenFileDialog return command line argument RRS feed

  • General discussion

  • I have one application having command line argument.

    Want to open it using OpenFileDialog but not getting proper targetpath of application with command line argument.

    can anybody tell me how to get it?

    Regards,

    Cauveri.

    Wednesday, June 25, 2014 12:16 PM

All replies

  • System.Diagnostics.Process.Start("CMD.exe", "your command");

    regards

    joon


    • Edited by Joon84 Wednesday, June 25, 2014 12:59 PM
    Wednesday, June 25, 2014 12:59 PM
  • in my other application say A on "Open App" button opening "OpenFileDialog" .

    Selecting application B's shortcut so getting the install location path of application B through dialog.

    But application B having parameter say "arg1".

    How to access this parameter using "OpenFileDialog" or application path.

    Regards,

    Cauveri

    Thursday, June 26, 2014 4:54 AM
  • You mean you want to find the exe using openfiledialog?

    http://blogs.msdn.com/b/wpfsdk/archive/2010/03/26/openfiledialog-sample.aspx

    Note the string filename line which gets the path.You then do the start:

    System.Diagnostics.Process.Start(filename, "your command");

    Where filename is that same variable in the link.

    Thursday, June 26, 2014 7:58 AM
  • path I'm getting.

    But application B having parameter say "arg1".

    How to access this parameter

    Thursday, June 26, 2014 8:06 AM
  • See that "your command" that's the parameter.

    From

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.110).aspx

    Start(String, String)  Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component.  

    I would also strongly recommend you get used to looking up and reading entries on msdn.

    That stuff is your technical manual.

    Could you please remember to mark replies which help and or answer your question.
    • Edited by Andy ONeill Thursday, June 26, 2014 8:11 AM
    Thursday, June 26, 2014 8:11 AM
  • I don't want to start the process.

    Want to display application B with it's icon...but not getting correct icon.

    To get correct icon I need command line argument.

    Thursday, June 26, 2014 8:47 AM
  • A command line argument is only read by a programme when your run it.

    Start runs the programme.

    If a command line argument is involved then that means running something to me.

    If you instead want to show a list of exe in a grid or something, please explain.

    Thursday, June 26, 2014 9:01 AM
  • In application A want to display list of 5 applications.

    E.g. Application B which is having command line argument.

    I'm not getting the correct icon of application B as it's having command line argument.

    Thursday, June 26, 2014 9:06 AM
  • The icon displayed next to an exe has no dependency on whether there is a command line argument or not.

    You're not explaining something.

    Thursday, June 26, 2014 10:16 AM
  • My bottom line is how to get application shortcut full "Target"?

    Thursday, June 26, 2014 11:49 AM
  • I still don't understand.
    How is that different from the file path obtained from the openfiledialog example I posted a link to above?

    You're not explaining what you need.

    Thursday, June 26, 2014 1:40 PM
  • just create shortcut of any application having command line arguments on desktop.

    Check it's properties,you will see "target" property of application shortcut.

    I want to access it programmatically.

    Friday, June 27, 2014 4:53 AM
  • You will need to know the command line arguments.

    You have the link gets you the Location = the path to the exe.

    See this link:

    http://stackoverflow.com/questions/4897655/create-shortcut-on-desktop-c-sharp

    Friday, June 27, 2014 9:20 AM
  • Hi,

    If you want to get the Application command line of a process already launched, you can use a WMI Query to retrieve it.

    Here's a sample where I get the command line of an exe "test.exe" :

    try
    {
    	SelectQuery query = new SelectQuery("select * from Win32_Process where Name='test.exe'");
    	ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
    	foreach (ManagementObject mObj in searcher.Get())
    	{
    		Debug.WriteLine("Commandline : {0}", mObj.Properties["CommandLine"].Value);
    	}
    }
    catch (Exception exc)
    {
    	MessageBox.Show(this, exc.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
    }

    Here, I used the Win32_Process class of WMIs.

    You'll have to inclure the "System.Management" assembly in your project and add a "using System.Management" clause.

    Is this what you were looking for?


    Philippe



    • Edited by PhGr_ Friday, June 27, 2014 9:50 AM
    Friday, June 27, 2014 9:43 AM
  • thanks for your efforts.

    But my question is different.

    I have application A.

    To launch it I need to provide some command line argument in project properties.

    Created it's shortcut at desktop.

    Go to properties of application shortcut.

    Check "Target" property,it contains "application installed path + command line argument"

    But when accessing it programmatically getting only application installed path.

    I want to access "Target" property of shortcut.

    Friday, June 27, 2014 10:27 AM
  • Oh sorry for misunderstanding... However this could always be usefull for other stuff...

    Well, if you want to have some shortcuts properties, you'll have to use COM objects :

    include a reference to "Windows Script Host object Model" in your project (you'll find it under the COM section).

    Then, you can get some information specific to shortcuts, in particular the commandline :

    IWshRuntimeLibrary.WshShell test = new IWshRuntimeLibrary.WshShell();
    IWshRuntimeLibrary.IWshShortcut scut =
    	test.CreateShortcut(@"C:\Users\MyUser\Desktop\MyShortcut.lnk");
    _tbTest.Text = string.Format("Target = '{0}' ; Arguments= {1} ; Icon location = {2}",
    	scut.TargetPath, scut.Arguments, scut.IconLocation);


    Philippe


    • Edited by PhGr_ Friday, June 27, 2014 11:17 AM
    Friday, June 27, 2014 11:13 AM