如題 怎麼實現??? 有高手留一下聯系方式麼~~跪求
如題 怎麼實現??? 有高手留一下聯系方式麼~~跪求如題 怎麼實現???
//打開服務控制管理器
SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCM == NULL)
{
return FALSE;
}
// Get the executable file path
TCHAR szFilePath[MAX_PATH];
::GetModuleFileName(NULL, szFilePath, MAX_PATH);
//創建服務
SC_HANDLE hService = ::CreateService(
hSCM, szServiceName, szServiceName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
szFilePath, NULL, NULL, L"", NULL, NULL);
if (hService == NULL)
{
::CloseServiceHandle(hSCM);
return FALSE;
}
//改變服務描述
SERVICE_DESCRIPTION Description;
TCHAR szDescription[1024];
ZeroMemory(szDescription, 1024);
ZeroMemory(&Description, sizeof(SERVICE_DESCRIPTION));
lstrcpy(szDescription, _T("服務的描述."));
Description.lpDescription = szDescription;
::ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &Description);
//開始服務
::StartService(hService,0,NULL);
::CloseServiceHandle(hService);
::CloseServiceHandle(hSCM);