carlostriassi
asked on
ProcessStartInfo - execute a command from windows service
I run this from dos prompt and it works
c:\windows\system32\cmd.ex
open a network connection.
I have Windows Service C# program that does the following:
string command = string.Format (@"net use \\{0}\IPC$ /user:{1} {2}", "win_xp_pro", "administrator", "1234");
ProcessStartIfo ps = new ProcessStartInfo();
ps.Filename = System.Environment.GetEnvi
ps.Arguments = "/C " + command;
ps.UseShellExecute = false;
ps.CreateNoWindow = true; // try both true or false
ps.RedirectStardardOutput = true;
Process process = Process.Start(ps);
process.WaitForExit();
int exitCode = Process.ExitCode;
process.Close();
It always return exit code = 2, which means File not found.
This program above work on a windows application, but I'm having trouble running as a windows service. Eventually, I want to create a batch file that establish connection, do some stuff, and close connection. I'll modify the above code to execute the batch file.
Any ideas?
Thanks,
Carlos.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.