The following code is throwing Exception. I don\'t get what mistake I am making in the code. Can somebody help me figure out please. I think it is of some security rights issue.
If you are already having the Service user as LocalSystem(the high privilage user) the problem is not security. Also I had that problem before and its the status vrs starting it again or stopping it when already commande to stop().
You see the service status its not changed on demand, so even if you coded
//this will start the process but the
//sc status will take some time to change
//when that happens and you try to start
//the already started service it will give you
//your error
servicec.start();
Soo you need to do this: msdn ServiceController.waitforstatus
Dim sc As New ServiceController
sc.ServiceName = "DataLoad"
If sc.Status = ServiceControllerStatus.Stopped Then
sc.Start()
// this makes it wait for the status to change
// and no it wont slow down anything at all.
sc.waitforstatus(ServiceControllerStatus.started)
Else
sc.Stop()
sc.waitforstatus(ServiceControllerStatus.stopped)
End If
This will solve your problem like it did mine.