running CommandPrompt from a Windows Service
I have a Windows Service that will create a Process object and fire the command prompt with a specific command. The problem I am having is that apparently the command prompt is trying to open a window and I am getting the following error:
Error: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application. (System.InvalidOperationException)
Can anyone help me to make this fire in the background using a windows service or do I have to go another way?
Posted Nov 3, 2009, 11:35 PM
string commandLine = "notepad.exe";
ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
PSI.CreateNoWindow = false;
Process p = Process.Start(PSI);
System.IO.StreamWriter SW = p.StandardInput;
System.IO.StreamReader SR = p.StandardOutput;
SW.WriteLine(commandLine);
SW.Close();
Here replace the command line string with the process u want to run or aanything u want to do..Here i have opened a notepad file..
Hope this helps....Fell free to ask..
----------------------------------------------------------------------------------------------
If my answer helped u don't forget to mark it as correct answer
Tracy BairdPosted Nov 3, 2009, 1:11 PM
Posted Nov 3, 2009, 12:24 PM
Here is an article which shows step by step to create a windows service.
http://aspalliance.com/1316_Working_with_Windows_Service_Using_Visual_Studio_2005.all
Hope it helps.
-----------------------------------------------------------------------------------------------
If my answer helped u don't forget to mark it as correct answer