Click here to Skip to main content
15,886,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected override void OnStart(string[] args)
{
    string targetDir = string.Format(args[0]);
    proc = new Process();
    proc.StartInfo.WorkingDirectory = targetDir;
    proc.StartInfo.FileName = args[1];
    proc.Start();
}

protected override void OnStop()
{
    proc.Kill();
}

in myservices.msc, I give parameters as "directory" "batch file name" .
The service starts successfully, but it does not stop.

How do I make it stop?

Thanks and Regards,
Anju
Posted
Updated 20-May-13 20:13pm
v3
Comments
Ezra Neil 21-May-13 2:13am    
Stop as in stop the actual service or just make the service run but not actually do anything? To stop service from running, you have to stop the actual service itself.
Zoltán Zörgő 21-May-13 2:16am    
Let's clarify You start a process from the service, and you are trying to stop it when service is stopping. What kind of process do you start? Have you checked with ProcessExplorer for example what's happening behind the scenes - is the process started, killed?
anju.gopinath 21-May-13 3:05am    
I am starting a batch file which ultimately calls a java file.

public static void main( String[] args )
{
WrapperManager.start( new TaskControllerService(), args );
}

i think you should use Service Controller object to stop a service
ServiceController service = new ServiceController("ServiceName");
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
 
Share this answer
 
Here is a basic article that would help you - http://www.csharp-examples.net/restart-windows-service/[^].
Of course, you need admin privileges to start and stop services.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900