Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
ProcessStartInfo procStartInfo = new ProcessStartInfo();
procStartInfo.FileName = "cmd.exe";
procStartInfo.Arguments = "/c cd../..";
//procStartInfo.Arguments = "/c cd c:\\windows\\";
procStartInfo.Arguments = "/c cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319";
procStartInfo.Arguments = "installutil/i /c C:\\Users\\kk\\Desktop\\Winservice\\sampleService.exe"
Posted
Comments
Sergey Alexandrovich Kryukov 29-Nov-15 11:47am    
Don't use "CMD"; it is totally irrelevant.
—SA

1 solution

If that is a copy and paste an obvious problem is:

C#
procStartInfo.Arguments = "installutil/i /c C:\\Users\\kk\\Desktop\\Winservice\\sampleService.exe"



Should be


C#
procStartInfo.Arguments = installutil /i /c "C:\\Users\\kk\\Desktop\\Winservice\\sampleService.exe"


Also, are you sure you should be escaping the \

You might find that this works fine:

C#
procStartInfo.Arguments = installutil /i /c "C:\Users\kk\Desktop\Winservice\sampleService.exe"




Read this: Install a .Net Service.

You should also read this article: InstallUtil MSDN

You may find this interesting: Installing a Windows Service using P Invoke in C#
 
Share this answer
 
v4
Comments
johannesnestler 30-Nov-15 10:19am    
Good links, but your "obvious problem" analysis seems a bit faulted. First OP states that he get's "unable to install" error. - so no, his parameter-Syntax isn't wrong, I'd say...
this is not compilable: procStartInfo.Arguments = installutil /i /c "C:\\Users\\kk\\Desktop\\Winservice\\sampleService.exe"
You may meant something like this? procStartInfo.Arguments = "installutil /i /c \"C:\\Users\\kk\\Desktop\\Winservice\\sampleService.exe\"" - a quoted path inside the Argument string - but in OP's case not needed because he has no spaces in his path - sure good code looks not like this - but that's not OP's problem at hand.
[no name] 30-Nov-15 11:23am    
Please ramble somewhere else.
johannesnestler 1-Dec-15 6:58am    
;) - Ok...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900