{
SC_HANDLE hSc;
SERVICE_STATUS Status;
-
+
+#ifdef SCDBG
/* testing */
_tprintf(_T("service to control - %s\n\n"), ServiceName);
_tprintf(_T("command - %lu\n\n"), Control);
printf("%s\n", *Args);
Args++;
}
-
+#endif /* SCDBG */
hSc = OpenService(hSCManager, ServiceName,
SERVICE_INTERROGATE | SERVICE_PAUSE_CONTINUE |
if (! ControlService(hSc, Control, &Status))
{
- _tprintf(_T("controlService failed\n"));
+ _tprintf(_T("[SC] controlService FAILED %lu:\n\n"), GetLastError());
ReportLastError();
return FALSE;
}
if ((! ServiceName) || (! BinaryPathName))
return CreateUsage();
-
+
+#ifdef SCDBG
/* testing */
printf("service to create - %s\n", ServiceName);
printf("Binary path - %s\n", BinaryPathName);
printf("%s\n", *Options);
Options++;
}
-
+#endif
hSc = CreateService(hSCManager,
ServiceName,
ServiceName,
ReportLastError();
return FALSE;
}
- else
- {
- CloseServiceHandle(hSc);
- return TRUE;
- }
+
+ _tprintf(_T("[SC] CreateService SUCCESS\n"));
+ CloseServiceHandle(hSc);
+ return TRUE;
}
_tprintf(_T("Remote service control is not yet implemented\n"));
return 2;
}
-
- hSCManager = OpenSCManager(MachineName, NULL, SC_MANAGER_ALL_ACCESS);
+
+ /* if we are emurating the services, we don't need administrator access */
+ if ( (_tcsicmp(Command, _T("query")) == 0) || (_tcsicmp(Command, _T("queryex")) == 0) )
+ hSCManager = OpenSCManager(MachineName, NULL, SC_MANAGER_ENUMERATE_SERVICE);
+ else
+ hSCManager = OpenSCManager(MachineName, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
{
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
{
SC_HANDLE hSc;
- SERVICE_STATUS_PROCESS ServiceStatus;
+ SERVICE_STATUS_PROCESS ServiceStatus, ServiceStatus2;
DWORD BytesNeeded;
+#ifdef SCDBG
/* testing */
_tprintf(_T("service to start - %s\n\n"), ServiceName);
_tprintf(_T("Arguments :\n"));
printf("%s\n", *ServiceArgs);
ServiceArgs++;
}
-
+#endif
/* get a handle to the service requested for starting */
hSc = OpenService(hSCManager, ServiceName, SERVICE_ALL_ACCESS);
/* start the service opened */
if (! StartService(hSc, ArgCount, ServiceArgs))
{
- _tprintf(_T("StartService failed\n"));
+ _tprintf(_T("[SC] StartService FAILED %lu:\n\n"), GetLastError());
ReportLastError();
return FALSE;
}
}
}
+ QueryServiceStatusEx(hSc, SC_STATUS_PROCESS_INFO, (LPBYTE)&ServiceStatus2,
+ sizeof(SERVICE_STATUS_PROCESS), &BytesNeeded);
+
CloseServiceHandle(hSc);
if (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
{
- _tprintf(_T("%s is running\n"), ServiceName);
+ _tprintf(_T("\nSERVICE_NAME: %s\n"), ServiceName);
+ _tprintf(_T("\tTYPE : %lu\n"), ServiceStatus2.dwServiceType);
+ _tprintf(_T("\tSTATE : %lu\n"), ServiceStatus2.dwCurrentState);
+ _tprintf(_T("\tWIN32_EXIT_CODE : %lu\n"), ServiceStatus2.dwWin32ExitCode);
+ _tprintf(_T("\tCHECKPOINT : %lu\n"), ServiceStatus2.dwCheckPoint);
+ _tprintf(_T("\tWAIT_HINT : %lu\n"), ServiceStatus2.dwWaitHint);
+ _tprintf(_T("\tPID : %lu\n"), ServiceStatus2.dwProcessId);
+ _tprintf(_T("\tFLAGS : %lu\n"), ServiceStatus2.dwServiceFlags);
+
return TRUE;
}
else