Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 414149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:15:15+00:00 2026-05-12T18:15:15+00:00

From the registry, for a given file type, I get a string containing something

  • 0

From the registry, for a given file type, I get a string containing something like this:

"C:\Program Files\AppName\Executable.exe" /arg1 /arg2 /arg3

or sometimes:

"C:\Program Files\AppName\Executable.exe" /arg1 /arg2 /arg3 "%1"

In order for me to execute this program, and pass along a filename as a parameter (which I know it accepts), do I have to parse this string myself, or is there a runtime class that will do this for me? Note that I’m not asking about handling the difference between the two in regards to whether it has a “%1” or not, but rather I need to split off the name of the executable, get the command line arguments to it separately.

I tried just appending/injecting the full path to and name of the file to pass along into the string above and pass the whole shebang to Process.Start, but of course it expects just the filename as the single argument, so that doesn’t work.

Basically, the above would have to be done like this manually:

Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files\AppName\Executable.exe";
proc.StartInfo.Arguments = "/arg1 /arg2 /arg3 \"" + fileName + "\"";
proc.Start();

I tried using UseShellExecute, but that didn’t help. Any other pointers?

To be clear, I want this:

String commandPath = ReadFromRegistry();
String fullCommand = commandPath + " " + fileName; // assuming not %1
Process.Start(fullCommand); // <-- magic happens here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:15:15+00:00Added an answer on May 12, 2026 at 6:15 pm

    The problem you are facing is that the executable name and some arguments are already together in your variable commandPath (which is not only the path, but also some params). If the first part were only made up of characters (no spaces), it wouldn’t have been too hard to separate the executable from the params, but this is Windows, so you may have spaces, so you are stuck. So it seems.

    The solution is in not using Process.Start, and not using ShellExecute. Process.Start, whether you ask it to use ShellExecute or CreateProcess, in both cases, it requires the FileName parameter/member to be set, which is passed as-is to CreateProcess and ShellExecute.

    So what then? Rather simply put: use CreateProcess yourself. A lesser known feature of that API function is that you can pass a full commandline to it, just as you can under WinKey+R (Windows Run). The “magic” that you ask for can be achieved by setting its first param to null and its second param to the full path, including all parameters. Like the following, which will start the Windows Photo Gallery for you, while using the same string with the params with Process.Start any which way would yield a “File Not Found” error:

    STARTUPINFO si = new STARTUPINFO();
    PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
    CreateProcess(
        /* app name     */ null,
        /* cmd line     */ @"C:\Program Files\Windows Photo Gallery\WindowsPhotoGallery.exe testBogusParam", 
        /* proc atts    */ IntPtr.Zero, 
        /* thread atts  */ IntPtr.Zero, 
        /* inh handles  */ false,
        /* create flags */ 0, 
        /* env ptr      */ IntPtr.Zero, 
        /* current dir  */ null, 
        /* startupinfo  */ ref si, 
        /* processinfo  */ out pi);
    

    Note that I deliberately did not include quotes around the executable path. But if the executable path has quotes around it, as with your code above, it will still work, all the magic is there. Combine that with your code snippet, the following will start the process the way you want:

    /* with your code */
    String commandPath = ReadFromRegistry();
    String fullCommand = commandPath + " " + fileName; // assuming not %1
    STARTUPINFO si = new STARTUPINFO();
    PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
    CreateProcess(
        null,
        fullCommand, 
        IntPtr.Zero, 
        IntPtr.Zero, 
        false,
        0, 
        IntPtr.Zero, 
        null, 
        ref si, 
        out pi);
    

    The declarations are something you can get from http://www.pinvoke.net, but for convenience, here’s the part that should be pasted inside the class section to get the above to work. Reference of these functions, how to check the result (success / fail) and the STARTUPINFO and PROCESS_INFORMATION structures can be found at Microsoft’s MSDN here. for convenience, I recommend to place the call to CreateProcess in a utility function.

    /* place the following at the class level */
    [DllImport("kernel32.dll")]
    static extern bool CreateProcess(
        string lpApplicationName, 
        string lpCommandLine, 
        IntPtr lpProcessAttributes, 
        IntPtr lpThreadAttributes,
        bool bInheritHandles, 
        uint dwCreationFlags, 
        IntPtr lpEnvironment,
        string lpCurrentDirectory, 
        ref STARTUPINFO lpStartupInfo,
        out PROCESS_INFORMATION lpProcessInformation);
    
    public struct PROCESS_INFORMATION
    {
        public IntPtr hProcess;
        public IntPtr hThread;
        public uint dwProcessId;
        public uint dwThreadId;
    }
    
    
    
    public struct STARTUPINFO
    {
        public uint cb;
        public string lpReserved;
        public string lpDesktop;
        public string lpTitle;
        public uint dwX;
        public uint dwY;
        public uint dwXSize;
        public uint dwYSize;
        public uint dwXCountChars;
        public uint dwYCountChars;
        public uint dwFillAttribute;
        public uint dwFlags;
        public short wShowWindow;
        public short cbReserved2;
        public IntPtr lpReserved2;
        public IntPtr hStdInput;
        public IntPtr hStdOutput;
        public IntPtr hStdError;
    }
    

    Hope I understood your problem correctly. Let me know if you have trouble implementing the above code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 196k
  • Answers 196k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Parentheses around a number to indicate it's a debit (i.e.… May 12, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer You're using SOAP as you say yourself - which means,… May 12, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer If you want to keep this as one column, use… May 12, 2026 at 7:08 pm

Related Questions

I've got a small program that displays third-party generated HTML pages. It's really just
We are running a .Net 1.1 based Windows Service ( not an ASP.Net application),
I have started coding an FTP client application (for fun). I’m trying to represent
Is there a tool to generate WiX XML given a .reg file? In 2.0,
Third party vendors using our software as a component view Windows Logo Certification as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.