zoukankan      html  css  js  c++  java
  • ChangeServiceConfig2设置SERVICE_CONFIG_FAILURE_ACTIONS

     SERVICE_FAILURE_ACTIONS sdBuf={0};
        BOOL bSuccess=TRUE;
     
     if (argc!=2)
     {
      return 1;
     }
        // Open a handle to the service.
     SC_HANDLE sch=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
     if (sch==NULL)
     {
      return 1;
     }
        SC_HANDLE schService = OpenService(
            sch,           // SCManager database
            argv[1],    // name of service
            SC_MANAGER_ALL_ACCESS); // need CHANGE access

        if (schService == NULL)
        {
            printf("OpenService failed (%d)\n", GetLastError());
            return FALSE;
        }

        sdBuf.lpRebootMsg=NULL;
     sdBuf.dwResetPeriod=3600*24;

     SC_ACTION action[3];

     action[0].Delay=60*1000;
     action[0].Type=SC_ACTION_RESTART;

     action[1].Delay=0;
     action[1].Type=SC_ACTION_NONE;
     action[2].Delay=0;
     action[2].Type=SC_ACTION_NONE;

     sdBuf.cActions=3;
     sdBuf.lpsaActions=action;
     sdBuf.lpCommand=NULL;

        if( !ChangeServiceConfig2(
            schService,                
            SERVICE_CONFIG_FAILURE_ACTIONS,
            &sdBuf) )                  
        {
            printf("%s ChangeServiceConfig2 failed\n",argv[1]);
            bSuccess = FALSE;
        }
        else
            printf("%s ChangeServiceConfig2 succeeded\n",argv[1]);
     
        CloseServiceHandle(schService);

  • 相关阅读:
    51nod 1067 Bash游戏 V2
    洛谷 P1454 圣诞夜的极光 == codevs 1293 送给圣诞夜的极光
    bzoj4754: [Jsoi2016]独特的树叶
    bzoj 4241: 历史研究
    bzoj 1266 [AHOI2006] 上学路线
    bzoj4571: [Scoi2016]美味
    bzoj4570: [Scoi2016]妖怪
    51nod 1238 最小公倍数之和 V3
    一个康托展开的板子
    poweroj1745: 餐巾计划问题
  • 原文地址:https://www.cnblogs.com/ahuo/p/1442941.html
Copyright © 2011-2022 走看看