Executing Shell Command
-
Hi, I have trouble in executing shell commands within windows service. Below is my code in Timers Elapsed event. Timers interval is 5 sec. Other than this code everything else is working. I am not sure why I am unable to execute this code. I am running my windows service as a User, which has administrator rights. I also tried to run this windows service as LocalSystem but nothing happens. Have a nice day. Naqsh Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process() proc.StartInfo.FileName = "cmd.exe" proc.StartInfo.Arguments = "/C net start ""IIS Admin""" proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden proc.StartInfo.CreateNoWindow = True proc.Start() End Sub Justice and Peace for everyone.
-
Hi, I have trouble in executing shell commands within windows service. Below is my code in Timers Elapsed event. Timers interval is 5 sec. Other than this code everything else is working. I am not sure why I am unable to execute this code. I am running my windows service as a User, which has administrator rights. I also tried to run this windows service as LocalSystem but nothing happens. Have a nice day. Naqsh Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process() proc.StartInfo.FileName = "cmd.exe" proc.StartInfo.Arguments = "/C net start ""IIS Admin""" proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden proc.StartInfo.CreateNoWindow = True proc.Start() End Sub Justice and Peace for everyone.
That's because (I THINK!!) CMD will only launch on Desktop 0, what the user sees. You can't launch CMD from a service because the service has no visible desktop and has no access to interactive inputs (keyboard and mouse), which CMD requires. What you should be doing is using the ServiceController class to start the IIS Admin Service. This is done something like this:
Dim myController As New System.ServiceProcess.ServiceController("IISAdmin") If myController.Status.Equals(ServiceControllerStatus.Stopped) Then myController.Start() End If
RageInTheMachine9532