服务项开启程序代码

来源:互联网 发布:双喜软件价格 编辑:程序博客网 时间:2024/05/22 20:51

BOOL ServiceStart(const wchar_t *wcsServiceName)
{
  SC_HANDLE hSCManager;
  SC_HANDLE hService;
  BOOL result=FALSE;

  hSCManager=OpenSCManagerW(NULL,NULL,SC_MANAGER_CONNECT);
  if(hSCManager!=NULL)
  {
  hService=OpenServiceW(hSCManager,wcsServiceName,SERVICE_START);
  if(hService!=NULL)
  {
  result=StartService(hService,0,NULL);

  CloseServiceHandle(hService);
  }
   
  CloseServiceHandle(hSCManager);
  }
  return(result);
}

原创粉丝点击