Install and uninstall windows service via command prompt "C#" -


i want install , uninstall win service via command prompt "c#"

following code not working please me

string strinstallutilpath ="c:\\windows\\microsoft.net\\framework\\v2.0.50727\\"; string strinstallservice = " installutil.exe \"d:\\testuser\\serviceforpatch\\testservice\\bin\\debug\\testservice.exe\"";                            processstartinfo psi = new processstartinfo("cmd.exe"); psi.redirectstandardinput = true; psi.redirectstandardoutput = true; psi.redirectstandarderror = true; psi.useshellexecute = false; process p = process.start(psi); system.io.streamwriter sw = p.standardinput; system.io.streamreader sr = p.standardoutput; sw.writeline(@"cd\");          sw.writeline(@"cd " + strinstallutilpath); sw.writeline(strinstallservice); p.waitforexit();  sw.close(); 

you don't need start command prompt. have start installutil , pass appropriate paramters.

modified code snippet, invokes installutil options , writes output string , on console window.

        string strinstallutilpath = @"c:\\windows\\microsoft.net\\framework\\v2.0.50727\\installutil.exe";         string strinstallservice = @"d:\testuser\serviceforpatch\testservice\bin\debug\testservice.exe";          processstartinfo processstartinfo  =              new processstartinfo(strinstallutilpath, string.format("/i {0}", strinstallservice));           processstartinfo.redirectstandardoutput = true;         processstartinfo.redirectstandarderror = true;         processstartinfo.useshellexecute = false;          process process = new process();         process.startinfo = processstartinfo;         process.start();         process.waitforexit();          string output = process.standardoutput.readtoend();         console.writeline(output); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -