How to start service programmatically ?

polaris

Distinguished
Apr 29, 2001
63
0
18,630
Archived from groups: microsoft.public.vc.language,microsoft.public.vc.mfc,microsoft.public.windowsxp.security_admin (More info?)

Hi:

I wrote a service program on XP. The service can be started manually in the
Control Panel - Service program, but I could not start it programmatically;
call to StartService() returns Error message saying could not connect to the
Service Control Manager.

Appreciate any hits from you!

Thanks in Advance
Polaris
 
G

Guest

Guest
Archived from groups: microsoft.public.vc.language,microsoft.public.vc.mfc,microsoft.public.windowsxp.security_admin (More info?)

Could you post little Code snippet ,describing extactly how are using
StartService(...) api?
Have you tried taking valid HANDLE form OpenSCManager(...) with all
access.


--

With Regards
Alok Gupta
Visit me at http://alok.bizhat.com

"I Believe this will Help"


"Polaris" <etpolaris@hotmail.com> wrote in message
news:uRAwTcCNFHA.2252@TK2MSFTNGP15.phx.gbl...
> Hi:
>
> I wrote a service program on XP. The service can be started manually in
the
> Control Panel - Service program, but I could not start it
programmatically;
> call to StartService() returns Error message saying could not connect to
the
> Service Control Manager.
>
> Appreciate any hits from you!
>
> Thanks in Advance
> Polaris
>
>
 

polaris

Distinguished
Apr 29, 2001
63
0
18,630
Archived from groups: microsoft.public.vc.language,microsoft.public.vc.mfc,microsoft.public.windowsxp.security_admin (More info?)

Hi Thanks for your info. Below is the code I tried. For easier reading, I
have remved error checkings. The CreateService is successful, the service
shows up in the Control Panel - Services program and can be started there
too. But the StartService (hService) did not work. The status shown in the
Control Panel - Services program is always "Starting" and just hang there
and never finish. As you can see, I did use the SERVICE_ALL_ACCESS in
CreateService.

Please let me know if you can see something wrong here.

Thanks!

Polaris

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

SC_HANDLE hscm = OpenSCManager (NULL, SERVICES_ACTIVE_DATABASE,
SC_MANAGER_CREATE_SERVICE);

if (hscm)
{
SC_HANDLE hService = CreateService (hscm, g_szServiceName,
g_szDisplayName, SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS |
SERVICE_INTERACTIVE_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
path,
0, 0, 0, 0, 0);

StartService (hService);

if (hService)
CloseServiceHandle (hService);

CloseServiceHandle (hscm);
}


"thatsalok" <thatsalok@NO_gmail.com_I_DONT_NEED_SPAM> wrote in message
news:ehfDPrCNFHA.1436@TK2MSFTNGP10.phx.gbl...
> Could you post little Code snippet ,describing extactly how are using
> StartService(...) api?
> Have you tried taking valid HANDLE form OpenSCManager(...) with all
> access.
>
>
> --
>
> With Regards
> Alok Gupta
> Visit me at http://alok.bizhat.com
>
> "I Believe this will Help"
>
>
> "Polaris" <etpolaris@hotmail.com> wrote in message
> news:uRAwTcCNFHA.2252@TK2MSFTNGP15.phx.gbl...
>> Hi:
>>
>> I wrote a service program on XP. The service can be started manually in
> the
>> Control Panel - Service program, but I could not start it
> programmatically;
>> call to StartService() returns Error message saying could not connect to
> the
>> Service Control Manager.
>>
>> Appreciate any hits from you!
>>
>> Thanks in Advance
>> Polaris
>>
>>
>
>
 

polaris

Distinguished
Apr 29, 2001
63
0
18,630
Archived from groups: microsoft.public.vc.language,microsoft.public.vc.mfc,microsoft.public.windowsxp.security_admin (More info?)

Hi:
I tried the code again and it worked! I do not know why, the only thing I
can think of is that I rebooted the machine and that might re-set the
service control manager.

Thanks
Polaris

"thatsalok" <thatsalok@NO_gmail.com_I_DONT_NEED_SPAM> wrote in message
news:ehfDPrCNFHA.1436@TK2MSFTNGP10.phx.gbl...
> Could you post little Code snippet ,describing extactly how are using
> StartService(...) api?
> Have you tried taking valid HANDLE form OpenSCManager(...) with all
> access.
>
>
> --
>
> With Regards
> Alok Gupta
> Visit me at http://alok.bizhat.com
>
> "I Believe this will Help"
>
>
> "Polaris" <etpolaris@hotmail.com> wrote in message
> news:uRAwTcCNFHA.2252@TK2MSFTNGP15.phx.gbl...
>> Hi:
>>
>> I wrote a service program on XP. The service can be started manually in
> the
>> Control Panel - Service program, but I could not start it
> programmatically;
>> call to StartService() returns Error message saying could not connect to
> the
>> Service Control Manager.
>>
>> Appreciate any hits from you!
>>
>> Thanks in Advance
>> Polaris
>>
>>
>
>
 
G

Guest

Guest
Archived from groups: microsoft.public.vc.language,microsoft.public.vc.mfc,microsoft.public.windowsxp.security_admin (More info?)

Are you creating service every time before starting!!!!!, better use
OpenService(...) api to get valid handle of service then pass it on
StartService(...) api.


--

With Regards
Alok Gupta
Visit me at http://alok.bizhat.com

"I Believe this will Help"
"Polaris" <etpolaris@hotmail.com> wrote in message
news:#dxHhmJNFHA.1176@TK2MSFTNGP12.phx.gbl...
> Hi:
> I tried the code again and it worked! I do not know why, the only thing I
> can think of is that I rebooted the machine and that might re-set the
> service control manager.
>
> Thanks
> Polaris
>
> "thatsalok" <thatsalok@NO_gmail.com_I_DONT_NEED_SPAM> wrote in message
> news:ehfDPrCNFHA.1436@TK2MSFTNGP10.phx.gbl...
> > Could you post little Code snippet ,describing extactly how are using
> > StartService(...) api?
> > Have you tried taking valid HANDLE form OpenSCManager(...) with all
> > access.
> >
> >
> > --
> >
> > With Regards
> > Alok Gupta
> > Visit me at http://alok.bizhat.com
> >
> > "I Believe this will Help"
> >
> >
> > "Polaris" <etpolaris@hotmail.com> wrote in message
> > news:uRAwTcCNFHA.2252@TK2MSFTNGP15.phx.gbl...
> >> Hi:
> >>
> >> I wrote a service program on XP. The service can be started manually in
> > the
> >> Control Panel - Service program, but I could not start it
> > programmatically;
> >> call to StartService() returns Error message saying could not connect
to
> > the
> >> Service Control Manager.
> >>
> >> Appreciate any hits from you!
> >>
> >> Thanks in Advance
> >> Polaris
> >>
> >>
> >
> >
>
>