I am trying to write a c/c++ application that start/stop any windows service of my system.
My application is working fine for services that have no spaces in between their name, but for service names that have space between them are not responding.
Following are the commands i am using for opening service:
SC_HANDLE serviceDbHandle = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
SC_HANDLE serviceHandle = OpenService(serviceDbHandle,
"My Service",
SC_MANAGER_ALL_ACCESS);
Here "My Service"
- 2nd parameter is LPCSTR
and its null termination is creating problem.
How can i start/stop services that have spaces in their name - any clue or suggestions would be helpful.
Iam using Visual studio 2005 in xp machine.
Thanks,
Anil
You need to use the service's internal name (which has no spaces), not the display name (which may).
From MSDN:
The name of the service to be opened. This is the name specified by the
lpServiceName
parameter of theCreateService
function when the service object was created, not the service display name that is shown by user interface applications to identify the service.