Board index » Visual Studio » starting/ stopping a windows service

starting/ stopping a windows service

Visual Studio158
Hi,

Does somebody know how to start / stop and get a status of a 'windows

service' using MFC (or win32 api)?

Regards,

Ram.


-
 

Re:starting/ stopping a windows service

In article <eiUJzyWSEHA.2236@TK2MSFTNGP09.phx.gbl>,

ram_ba_ruch@newsgroups.nospam says...

Quote
Hi,

Does somebody know how to start / stop and get a status of a 'windows

service' using MFC (or win32 api)?



StartService, StopService and QueryServiceStatus. You might also

want to look at ControlService.



--

Later,

Jerry.



The universe is a figment of its own imagination.

-

Re:starting/ stopping a windows service



int StartService(LPSTR sService)

{

SC_HANDLE hSCM = OpenSCManager( "", SERVICES_ACTIVE_DATABASE,

SC_MANAGER_ALL_ACCESS );



if( !hSCM ) {

CloseServiceHandle(hSCM);

return 0;

}



SC_HANDLE hService = OpenService( hSCM, sService, SERVICE_ALL_ACCESS );

if( hService ) {

BOOL b = ::StartService( hService, 0, NULL );

}



CloseServiceHandle(hService);

CloseServiceHandle(hSCM);



return 1;



}



--

Best Regards

Suhredayan



Omniquad Ltd

www.omniquad.com">www.omniquad.com













"Ram Baruch" <ram_ba_ruch@newsgroups.nospam>wrote in message

Quote
Hi,

Does somebody know how to start / stop and get a status of a 'windows

service' using MFC (or win32 api)?

Regards,

Ram.









-

Re:starting/ stopping a windows service

thanks!



"suhredayan" <suhredayan@omniquad.com>wrote in message

Quote


int StartService(LPSTR sService)

{

SC_HANDLE hSCM = OpenSCManager( "", SERVICES_ACTIVE_DATABASE,

SC_MANAGER_ALL_ACCESS );



if( !hSCM ) {

CloseServiceHandle(hSCM);

return 0;

}



SC_HANDLE hService = OpenService( hSCM, sService, SERVICE_ALL_ACCESS );

if( hService ) {

BOOL b = ::StartService( hService, 0, NULL );

}



CloseServiceHandle(hService);

CloseServiceHandle(hSCM);



return 1;



}



--

Best Regards

Suhredayan



Omniquad Ltd

www.omniquad.com">www.omniquad.com













"Ram Baruch" <ram_ba_ruch@newsgroups.nospam>wrote in message

news:eiUJzyWSEHA.2236@TK2MSFTNGP09.phx.gbl...

>Hi,

>Does somebody know how to start / stop and get a status of a 'windows

>service' using MFC (or win32 api)?

>Regards,

>Ram.

>

>









-