• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetLastErrorText函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GetLastErrorText函数的典型用法代码示例。如果您正苦于以下问题:C++ GetLastErrorText函数的具体用法?C++ GetLastErrorText怎么用?C++ GetLastErrorText使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetLastErrorText函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: SLPDCmdStopService

/*--------------------------------------------------------------------------*/
void SLPDCmdStopService()
/*--------------------------------------------------------------------------*/
{
	 SC_HANDLE schService; 
	 SC_HANDLE schSCManager; 

	 schSCManager = OpenSCManager(
	 									  NULL,                   /* machine (NULL == local)    */
	 									  NULL,                   /* database (NULL == default) */
	 									  SC_MANAGER_ALL_ACCESS); /* access required    		  */
	 if(schSCManager)
	 {
	 	  schService = OpenService(schSCManager, G_SERVICENAME, SERVICE_ALL_ACCESS); 

	 	  if(schService)
	 	  {
	 			SLPDHlpStopService(schService);
	 			CloseServiceHandle(schService); 
	 	  }
	 	  else
	 	  {
	 			printf("OpenService failed - %s\n", GetLastErrorText(szErr,256)); 
	 	  }
	 	  CloseServiceHandle(schSCManager); 
	 }
	 else
	 {
	 	  printf("OpenSCManager failed - %s\n", GetLastErrorText(szErr,256)); 
	 }
}
开发者ID:ncultra,项目名称:openslp,代码行数:31,代码来源:slpd_win32.c


示例2: OpenSCManager

//停止服务
BOOL wx_service::StopService()
{
	char szError[512]={0};
	bool bRet = false;
	bPause = true;
	hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if( hSCM)               //   如果打开SERVICE管理器成功   
	{   
		hService   =  ::OpenService(         //获取SERVICE控制句柄的API   
			hSCM,                         //SCM管理器句柄   
			szServiceName,                 //SERVICE内部名称,控制名称   
			SERVICE_ALL_ACCESS);         //打开的权限,删除就要全部权限

		if(hService){
			if(QueryServiceStatus(hService,   &status)){
				if ( status.dwCurrentState != SERVICE_STOPPED )
				{
					if( ControlService(hService,   SERVICE_CONTROL_STOP, &status) ){
						bRet = true;
					}else
						LogEvent( GetLastErrorText(szError, 512) );
				}
			}
		}else
			LogEvent( GetLastErrorText(szError, 512) );

		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
	}else{
		LogEvent( GetLastErrorText(szError, 512) );
	}
	return bRet;
}
开发者ID:blackshadowwalker,项目名称:wx_kk_up,代码行数:35,代码来源:wx_kk_service.cpp


示例3: install_service

static int install_service()
{
    SC_HANDLE schService, schSCManager;
    char filename[_MAX_PATH+10];

    if (GetModuleFileName(NULL, filename, _MAX_PATH) == 0) {
        printf("Unable to install Mixmaster Service: %s\n", GetLastErrorText());
        return 1;
    }
    strcat(filename, " --run-svc");

    if (!(schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) {
        printf("OpenSCManager failed: %s\n", GetLastErrorText());
        return 1;
    }
    schService = CreateService(schSCManager, SVCNAME, SVCDISPLAYNAME,
                               SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                               filename, NULL, NULL, NULL, NULL, NULL);

    if (schService) {
        printf("Mixmaster Service installed.\n");
        CloseServiceHandle(schService);
    } else {
        printf("CreateService failed: %s\n", GetLastErrorText());
    }

    CloseServiceHandle(schSCManager);
    return 0;
} /* install_service */
开发者ID:crooks,项目名称:mixmaster,代码行数:29,代码来源:service.c


示例4: CmdRemoveService

void CmdRemoveService(LPCSTR name)
{
    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;
    char        realName[512];

    sprintf(realName,"shibd_%s",name);

    schSCManager = OpenSCManager(
                        NULL,                   // machine (NULL == local)
                        NULL,                   // database (NULL == default)
                        SC_MANAGER_ALL_ACCESS   // access required
                        );
    if ( schSCManager )
    {
        schService = OpenService(schSCManager, realName, SERVICE_ALL_ACCESS);

        if (schService)
        {
            // try to stop the service
            if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) )
            {
                printf("Stopping shibd (%s).", name);
                Sleep( 1000 );

                while( QueryServiceStatus( schService, &ssStatus ) )
                {
                    if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING )
                    {
                        printf(".");
                        Sleep( 1000 );
                    }
                    else
                        break;
                }

                if ( ssStatus.dwCurrentState == SERVICE_STOPPED )
                    printf("\n%s stopped.\n", realName);
                else
                    printf("\n%s failed to stop.\n", realName);

            }

            // now remove the service
            if( DeleteService(schService) )
                printf("%s removed.\n", realName);
            else
                printf("DeleteService failed - %s\n", GetLastErrorText(szErr,256));


            CloseServiceHandle(schService);
        }
        else
            printf("OpenService failed - %s\n", GetLastErrorText(szErr,256));

        CloseServiceHandle(schSCManager);
    }
    else
        printf("OpenSCManager failed - %s\n", GetLastErrorText(szErr,256));
}
开发者ID:svn2github,项目名称:cpp-sp,代码行数:60,代码来源:shar_win32.cpp


示例5: CmdStartService

static int
CmdStartService (openvpn_service_type type)
{
  int ret = 1;
  SC_HANDLE svc_ctl_mgr;
  SC_HANDLE service;

  svc_ctl_mgr = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
  if (svc_ctl_mgr == NULL)
    {
      _tprintf (TEXT("OpenSCManager failed - %s\n"), GetLastErrorText ());
      return 1;
    }

  service = OpenService (svc_ctl_mgr, openvpn_service[type].name, SERVICE_ALL_ACCESS);
  if (service)
    {
      if (StartService (service, 0, NULL))
        {
          _tprintf (TEXT("Service Started\n"));
          ret = 0;
        }
      else
        _tprintf (TEXT("StartService failed - %s\n"), GetLastErrorText ());

      CloseServiceHandle(service);
    }
  else
    {
      _tprintf (TEXT("OpenService failed - %s\n"), GetLastErrorText ());
    }

  CloseServiceHandle(svc_ctl_mgr);
  return ret;
}
开发者ID:746bce42110a11028656eca33867,项目名称:openvpn,代码行数:35,代码来源:service.c


示例6: CmdInstallService

///////////////////////////////////////////////////////////////////
//
//  The following code handles service installation and removal
//
//
//  FUNCTION: CmdInstallService()
//
//  PURPOSE: Installs the service and Starts it
//
//  PARAMETERS:
//    argc: number of arguments
//	argv: all of the arguments including the program's name
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
void CmdInstallService(int argc, char **argv) {
    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;

    TCHAR szPath[512];

    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) {
        _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256));
        return;
    }

    schSCManager = OpenSCManager(
                                NULL,                   // machine (NULL == local)
                                NULL,                   // database (NULL == default)
                                SC_MANAGER_ALL_ACCESS   // access required
                                );
    if ( schSCManager ) {
        schService = OpenService(schSCManager, TEXT(SZSERVICENAME), SERVICE_ALL_ACCESS);
        if ( !schService ) {
            schService = CreateService(
                                      schSCManager,               // SCManager database
                                      TEXT(SZSERVICENAME),        // name of service
                                      TEXT(SZSERVICEDISPLAYNAME), // name to display
                                      SERVICE_ALL_ACCESS,         // desired access
                                      SERVICE_WIN32_OWN_PROCESS,  // service type
                                      SERVICE_DEMAND_START,       // start type
                                      SERVICE_ERROR_NORMAL,       // error control type
                                      szPath,                     // service's binary
                                      NULL,                       // no load ordering group
                                      NULL,                       // no tag identifier
                                      TEXT(SZDEPENDENCIES),       // dependencies
                                      NULL,                       // LocalSystem account
                                      NULL);                      // no password
        } else {
            _tprintf(TEXT("%s already installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
        }
        if ( schService ) {
            if ( QueryServiceStatus( schService, &ssStatus ) ) {
                int rc;
                if ( ssStatus.dwCurrentState == SERVICE_STOPPED ) {
                    rc = StartService(schService, argc-1, argv+1);
                }


                if ( rc != 0 )
                    _tprintf(TEXT("%s started.\n"), TEXT(SZSERVICEDISPLAYNAME) );
            }

            CloseServiceHandle(schService);
        } else {
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
        }

        CloseServiceHandle(schSCManager);
    } else
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));


}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:77,代码来源:service.c


示例7: CmdRemoveService

//
//  FUNCTION: CmdRemoveService()
//
//  PURPOSE: Stops and removes the service
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
void CmdRemoveService()
{
   SC_HANDLE   schService;
   SC_HANDLE   schSCManager;

   schSCManager = OpenSCManager(
                               NULL,                   // machine (NULL == local)
                               NULL,                   // database (NULL == default)
                               SC_MANAGER_CONNECT   // access required
                               );
   if ( schSCManager )
   {
      schService = OpenService(schSCManager, TEXT(SZSERVICENAME), DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);

      if (schService)
      {
         // try to stop the service
         if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) )
         {
            _tprintf(TEXT("Stopping %s."), TEXT(SZSERVICEDISPLAYNAME));
            Sleep( 1000 );

            while ( QueryServiceStatus( schService, &ssStatus ) )
            {
               if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING )
               {
                  _tprintf(TEXT("."));
                  Sleep( 1000 );
               }
               else
                  break;
            }

            if ( ssStatus.dwCurrentState == SERVICE_STOPPED )
               _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) );
            else
               _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) );

         }

         // now remove the service
         if ( DeleteService(schService) )
            _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
         else
            _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256));


         CloseServiceHandle(schService);
      }
      else
         _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));

      CloseServiceHandle(schSCManager);
   }
   else
      _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
}
开发者ID:SatishSara,项目名称:zxlooong,代码行数:70,代码来源:Service.c


示例8: CmdInstallService

//
//  FUNCTION: CmdInstallService()
//
//  PURPOSE: Installs the service
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    0 if success
//
//  COMMENTS:
//
int CmdInstallService()
{
   SC_HANDLE   schService;
   SC_HANDLE   schSCManager;

   TCHAR szPath[512];

   int ret = 0;

   if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
   {
      _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256));
      return 1;
   }

   schSCManager = OpenSCManager(
                               NULL,                   // machine (NULL == local)
                               NULL,                   // database (NULL == default)
                               SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE  // access required
                               );
   if ( schSCManager )
   {
      schService = CreateService(
                                schSCManager,               // SCManager database
                                TEXT(SZSERVICENAME),        // name of service
                                TEXT(SZSERVICEDISPLAYNAME), // name to display
                                SERVICE_QUERY_STATUS,         // desired access
                                SERVICE_WIN32_OWN_PROCESS,  // service type
            SERVICE_DEMAND_START,        // start type -- alternative: SERVICE_AUTO_START
                                SERVICE_ERROR_NORMAL,       // error control type
                                szPath,                     // service's binary
                                NULL,                       // no load ordering group
                                NULL,                       // no tag identifier
                                NULL, // TEXT(SZDEPENDENCIES),       // dependencies
                                NULL,                       // LocalSystem account
                                NULL);                      // no password

      if ( schService )
      {
         _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
         CloseServiceHandle(schService);
      }
      else
      {
         _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
    ret = 1;
      }

      CloseServiceHandle(schSCManager);
   }
   else
     {
      _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
       ret = 1;
     }
   return ret;
}
开发者ID:felipebuarque,项目名称:PL-Stats,代码行数:70,代码来源:win32_cservice.c


示例9: ReportEvent

//	PURPOSE:  Stops and removes the service
void CNTService::CmdRemoveService()
{
	char szErr[256];

	ReportEvent(EVENTLOG_INFORMATION_TYPE, 0, "Removing Service.");

	SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if ( !schSCManager )
	{
		ReportEvent(EVENTLOG_ERROR_TYPE, 0, "Remove OpenSCManager failed", GetLastErrorText(szErr, sizeof(szErr)));
		return;
	}

	// Try to obtain the handle of this service
	char szInternalName[MAX_PATH];
	sprintf(szInternalName, GRAY_TITLE " - %s", g_Serv.GetName());

	SC_HANDLE schService = OpenService(schSCManager, szInternalName, SERVICE_ALL_ACCESS);
	if ( !schService )
	{
		ReportEvent(EVENTLOG_ERROR_TYPE, 0, "Remove OpenService failed", GetLastErrorText(szErr, sizeof(szErr)));

		CloseServiceHandle(schSCManager);
		return;
	}

	// Check to see if the service is started, if so try to stop it.
	if ( ControlService(schService, SERVICE_CONTROL_STOP, &m_sStatus) )
	{
		ReportEvent(EVENTLOG_INFORMATION_TYPE, 0, "Stopping");

		Sleep(1000);
		while ( QueryServiceStatus(schService, &m_sStatus) )	// wait the service to stop
		{
			if ( m_sStatus.dwCurrentState == SERVICE_STOP_PENDING )
				Sleep(1000);
			else
				break;
		}

		if (m_sStatus.dwCurrentState == SERVICE_STOPPED)
			ReportEvent(EVENTLOG_INFORMATION_TYPE, 0, "Stopped");
		else
			ReportEvent(EVENTLOG_ERROR_TYPE, 0, "Failed to Stop");
	}

	// Remove the service
	if ( DeleteService(schService) )
		ReportEvent(EVENTLOG_INFORMATION_TYPE, 0, "Removed OK");
	else
		ReportEvent(EVENTLOG_ERROR_TYPE, 0, "Remove Fail", GetLastErrorText(szErr, sizeof(szErr)));

	CloseServiceHandle(schService);
	CloseServiceHandle(schSCManager);
}
开发者ID:DarkLotus,项目名称:Source,代码行数:56,代码来源:ntservice.cpp


示例10: DoSetPriority

static void DoSetPriority(DWORD priority)
{
    LVITEMW          lvitem;
    ULONG            Index, Count;
    DWORD            dwProcessId;
    HANDLE           hProcess;
    WCHAR            wstrErrorText[256];

    WCHAR    wszWarnMsg[255];
    WCHAR    wszWarnTitle[255];
    WCHAR    wszUnable2Change[255];

    LoadStringW(hInst, IDS_PRIORITY_CHANGE_MESSAGE, wszWarnMsg, sizeof(wszWarnMsg)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, sizeof(wszWarnTitle)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_PRIORITY_UNABLE2CHANGE, wszUnable2Change, sizeof(wszUnable2Change)/sizeof(WCHAR));

    Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
    for (Index=0; Index<Count; Index++)
    {
        lvitem.mask = LVIF_STATE;
        lvitem.stateMask = LVIS_SELECTED;
        lvitem.iItem = Index;
        lvitem.iSubItem = 0;

        SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM)&lvitem);

        if (lvitem.state & LVIS_SELECTED)
            break;
    }

    Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
    dwProcessId = PerfDataGetProcessId(Index);
    if ((Count != 1) || (dwProcessId == 0))
        return;

    if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
        return;

    hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);

    if (!hProcess)
    {
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Change, MB_OK|MB_ICONSTOP);
        return;
    }

    if (!SetPriorityClass(hProcess, priority))
    {
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Change, MB_OK|MB_ICONSTOP);
    }

    CloseHandle(hProcess);
}
开发者ID:AlexSteel,项目名称:wine,代码行数:55,代码来源:priority.c


示例11: CmdInstallService

// 
//  FUNCTION: CmdInstallService() 
// 
//  PURPOSE: Installs the service 
// 
//  PARAMETERS: 
//    none 
// 
//  RETURN VALUE: 
//    none 
// 
//  COMMENTS: 
// 
void CmdInstallService() 
{ 
    SC_HANDLE   schService; 
    SC_HANDLE   schSCManager; 
 
    TCHAR szPath[512]; 
 
    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) 
    { 
        _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256)); 
        return; 
    } 
 
    schSCManager = OpenSCManager( 
                        NULL,                   // machine (NULL == local) 
                        NULL,                   // database (NULL == default) 
                        SC_MANAGER_ALL_ACCESS   // access required 
                        ); 
    if ( schSCManager ) 
    { 
        schService = CreateService( 
            schSCManager,               // SCManager database 
            TEXT(SZSERVICENAME),        // name of service 
            TEXT(SZSERVICEDISPLAYNAME), // name to display 
            SERVICE_ALL_ACCESS,         // desired access 
            SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS ,  // service type 
            SERVICE_AUTO_START,       // start type 
            SERVICE_ERROR_NORMAL,       // error control type 
            szPath,                     // service's binary 
            NULL,                       // no load ordering group 
            NULL,                       // no tag identifier 
            TEXT(SZDEPENDENCIES),       // dependencies 
            NULL,                       // LocalSystem account 
            NULL);                      // no password 
 
        if ( schService ) 
        {   Sleep(1001);
            StartService(schService,0,0);
                        SC_ACTION sa={SC_ACTION_RESTART,60000};
                        SERVICE_FAILURE_ACTIONS sfa={60,0,0,1,&sa};
            ChangeServiceConfig2(schService,SERVICE_CONFIG_FAILURE_ACTIONS,&sfa);
            _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); 
            CloseServiceHandle(schService); 
        } 
        else 
        { 
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256)); 
        } 
 
        CloseServiceHandle(schSCManager); 
    } 
    else 
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); 
} 
开发者ID:afishbeck,项目名称:HPCC-Platform,代码行数:67,代码来源:newagent_se.cpp


示例12: CmdInstallService

//
//  FUNCTION: CmdInstallService()
//
//  PURPOSE: Installs the service
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
void CmdInstallService(char *Account,char *Password)
{
    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;

    TCHAR szPath[512];

    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
    {
        _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256));
        return;
    }

    schSCManager = OpenSCManager(
                        NULL,                   // machine (NULL == local)
                        NULL,                   // database (NULL == default)
                        SC_MANAGER_ALL_ACCESS   // access required
                        );
    if ( schSCManager )
    {
        schService = CreateService(
            schSCManager,               // SCManager database
            TEXT(SZSERVICENAME),        // name of service
            TEXT(SZSERVICEDISPLAYNAME), // name to display
            SERVICE_ALL_ACCESS,         // desired access
            SERVICE_WIN32_OWN_PROCESS,  // service type
            SERVICE_DEMAND_START,       // start type
            SERVICE_ERROR_NORMAL,       // error control type
            szPath,                     // service's binary
            NULL,                       // no load ordering group
            NULL,                       // no tag identifier
            TEXT(SZDEPENDENCIES),       // dependencies
            Account,                    // Administrator account
            Password);                  // password

        if ( schService )
        {
            _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
            CloseServiceHandle(schService);
			      AddEventSource();
            AddParametersRegistry();
        }
        else
        {
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
        }

        CloseServiceHandle(schSCManager);
    }
    else
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
}
开发者ID:bochaqos,项目名称:tol,代码行数:65,代码来源:SERVICE.C


示例13: CmdInstallServices

static int
CmdInstallServices()
{
    SC_HANDLE service;
    SC_HANDLE svc_ctl_mgr;
    TCHAR path[512];
    int i, ret = _service_max;

    if (GetModuleFileName(NULL, path + 1, 510) == 0)
    {
        _tprintf(TEXT("Unable to install service - %s\n"), GetLastErrorText());
        return 1;
    }

    path[0] = TEXT('\"');
    _tcscat(path, TEXT("\""));

    svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);
    if (svc_ctl_mgr == NULL)
    {
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText());
        return 1;
    }

    for (i = 0; i < _service_max; i++)
    {
        service = CreateService(svc_ctl_mgr,
                                openvpn_service[i].name,
                                openvpn_service[i].display_name,
                                SERVICE_QUERY_STATUS,
                                SERVICE_WIN32_SHARE_PROCESS,
                                openvpn_service[i].start_type,
                                SERVICE_ERROR_NORMAL,
                                path, NULL, NULL,
                                openvpn_service[i].dependencies,
                                NULL, NULL);
        if (service)
        {
            _tprintf(TEXT("%s installed.\n"), openvpn_service[i].display_name);
            CloseServiceHandle(service);
            --ret;
        }
        else
        {
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText());
        }
    }

    CloseServiceHandle(svc_ctl_mgr);
    return ret;
}
开发者ID:benjdag,项目名称:openvpn,代码行数:51,代码来源:service.c


示例14: CmdInstallService

//
//  FUNCTION: CmdInstallService()
//
//  PURPOSE: Installs the service
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
void CmdInstallService()
{
    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;

    TCHAR szPath[512];

    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
    {
        _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(szServiceDisplayName), GetLastErrorText(szErr, 256));
        return;
    }

    schSCManager = OpenSCManager(
                        NULL,                   // machine (NULL == local)
                        NULL,                   // database (NULL == default)
                        SC_MANAGER_ALL_ACCESS   // access required
                        );
    if ( schSCManager )
    {
        schService = CreateService(
            schSCManager,               // SCManager database
            TEXT(szServiceName),        // name of service
            TEXT(szServiceDisplayName), // name to display
            SERVICE_ALL_ACCESS,         // desired access
            SERVICE_WIN32_OWN_PROCESS,  // service type
            SERVICE_DEMAND_START,       // start type
            SERVICE_ERROR_NORMAL,       // error control type
            szPath,                     // service's binary
            NULL,                       // no load ordering group
            NULL,                       // no tag identifier
            TEXT(""),                   // dependencies
            NULL,                       // LocalSystem account
            NULL);                      // no password

        if ( schService )
        {
            _tprintf(TEXT("%s installed.\n"), TEXT(szServiceDisplayName) );
            CloseServiceHandle(schService);
        }
        else
        {
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
        }

        CloseServiceHandle(schSCManager);
    }
    else
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
}
开发者ID:AppliedLogicSystems,项目名称:ALSProlog,代码行数:63,代码来源:Service_Control.c


示例15: CmdRemoveService

static BOOL CmdRemoveService(void)
{
	SC_HANDLE schService = NULL;
	SC_HANDLE schSCManager = NULL;

	if ((schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) != NULL) {
		schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);

		if (schService != NULL) {
			if (ControlService(schService, SERVICE_CONTROL_STOP, &ssStatus)) {
				_tprintf(_T("Stopping %s."), szServiceDispName);
				Sleep(1000);

				while (QueryServiceStatus(schService, &ssStatus)) {
					if (ssStatus.dwCurrentState == SERVICE_STOP_PENDING) {
						_tprintf(_T("."));
						Sleep(1000);
					} else
						break;
				}

				if (ssStatus.dwCurrentState == SERVICE_STOPPED)
					_tprintf(_T("\n%s stopped.\n"), szServiceDispName);
				else
					_tprintf(_T("\n%s failed to stop.\n"), szServiceDispName);

			}

			if (DeleteService(schService)) {
				_tprintf(_T("%s removed.\n"), szServiceDispName);
				CloseServiceHandle(schService);
				CloseServiceHandle(schSCManager);

				return TRUE;
			} else
				_tprintf(_T("DeleteService failed - %s\n"),
					 GetLastErrorText(szErr, CountOf(szErr)));

			CloseServiceHandle(schService);
		} else
			_tprintf(_T("OpenService failed - %s\n"),
				 GetLastErrorText(szErr, CountOf(szErr)));

		CloseServiceHandle(schSCManager);
	} else
		_tprintf(_T("OpenSCManager failed - %s\n"),
			 GetLastErrorText(szErr, CountOf(szErr)));

	return FALSE;
}
开发者ID:linkclau,项目名称:XMail,代码行数:50,代码来源:MainWin.cpp


示例16: LOG_PRINT

    void Acceptor::listen()
    {
        socket_t fd = SocketOps::createSocket();

        if(fd < 0)
        {
            LOG_PRINT(LogType_Fatal, "create socket failed:%s %s:%d",
                      GetLastErrorText().c_str(), __FUNCTION__, __LINE__);
            return;
        }

        if(!SocketOps::bindSocket(fd, &listenAddr_.getSockAddr()))
        {
            LOG_PRINT(LogType_Fatal, "bind socket failed:%s %s:%d",
                      GetLastErrorText().c_str(), __FUNCTION__, __LINE__);
            goto err;
        }

        if(!SocketOps::listen(fd))
        {
            LOG_PRINT(LogType_Fatal, "listen socket failed:%s %s:%d",
                      GetLastErrorText().c_str(), __FUNCTION__, __LINE__);
            goto err;
        }

        if(!SocketOps::setSocketNoneBlocking(fd))
        {
            LOG_PRINT(LogType_Fatal, "enable socket noneBlocking failed:%s %s:%d",
                      GetLastErrorText().c_str(), __FUNCTION__, __LINE__);
            goto err;
        }

        LOG_PRINT(LogType_Info, "Acceptor listen at ip:%s port:%u", listenAddr_.ip().c_str(),
                  listenAddr_.port());

        listenFd_ = fd;
        acceptChannelPtr_ = std::make_shared<Channel>(loop_, listenFd_);
        acceptChannelPtr_->setReadCallback(std::bind(&Acceptor::handleRead, this));
        acceptChannelPtr_->setOwner(shared_from_this());
        acceptChannelPtr_->enableReading();
        listenning_ = true;

        return;

err:
        SocketOps::closeSocket(fd);
        return;
    }
开发者ID:pizishao,项目名称:project,代码行数:48,代码来源:Acceptor.cpp


示例17: ProcessPage_OnEndProcessTree

void ProcessPage_OnEndProcessTree(void)
{
    LVITEMW          lvitem;
    ULONG            Index;
    DWORD            dwProcessId;
    HANDLE           hProcess;
    WCHAR            wstrErrorText[256];

    load_message_strings();

    for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
    {
        lvitem.mask = LVIF_STATE;
        lvitem.stateMask = LVIS_SELECTED;
        lvitem.iItem = Index;
        lvitem.iSubItem = 0;

        SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);

        if (lvitem.state & LVIS_SELECTED)
            break;
    }

    dwProcessId = PerfDataGetProcessId(Index);

    if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
        return;

    if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
        return;

    hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);

    if (!hProcess)
    {
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
        return;
    }

    if (!TerminateProcess(hProcess, 0))
    {
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
    }

    CloseHandle(hProcess);
}
开发者ID:bilboed,项目名称:wine,代码行数:48,代码来源:endproc.c


示例18: CmdStartService

//
//  FUNCTION: CmdStartService()
//
//  PURPOSE: Start service if it exists
//
//  PARAMETERS:
//    argc: number of arguments
//	argv: arguments including program's name
//
//  RETURN VALUE:
//    TRUE: service exists and is started
//	FALSE: service doesn't exist
//
//  COMMENTS:
//
BOOL CmdStartService(int argc, char **argv) {
    BOOL isExist = FALSE;
    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;

    schSCManager = OpenSCManager(
                                NULL,                   // machine (NULL == local)
                                NULL,                   // database (NULL == default)
                                SC_MANAGER_ALL_ACCESS   // access required
                                );
    if ( schSCManager ) {
        schService = OpenService(schSCManager, TEXT(SZSERVICENAME), SERVICE_ALL_ACCESS);

        if ( schService ) {
            isExist = TRUE;
            if ( QueryServiceStatus( schService, &ssStatus ) ) {
                int rc;
                if ( ssStatus.dwCurrentState == SERVICE_STOPPED ) {
                    rc = StartService(schService, argc-1, argv+1);
                }


                if ( rc != 0 )
                    _tprintf(TEXT("%s started.\n"), TEXT(SZSERVICEDISPLAYNAME) );
            }
            CloseServiceHandle(schService);            
        }
        CloseServiceHandle(schSCManager);
    } else
        _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));

    return isExist;
}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:48,代码来源:service.c


示例19: MsgToEventLog

DWORD
MsgToEventLog (DWORD flags, LPCTSTR format, ...)
{
  HANDLE hEventSource;
  TCHAR msg[2][256];
  DWORD error = 0;
  LPCTSTR err_msg = TEXT("");
  va_list arglist;

  if (flags & MSG_FLAGS_SYS_CODE)
    {
      error = GetLastError ();
      err_msg = GetLastErrorText ();
    }

  hEventSource = RegisterEventSource (NULL, APPNAME);
  if (hEventSource != NULL)
    {
      openvpn_sntprintf (msg[0], _countof (msg[0]),
                         TEXT("%s%s: %s"), APPNAME,
                         (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT(""), err_msg);

      va_start (arglist, format);
      openvpn_vsntprintf (msg[1], _countof (msg[1]), format, arglist);
      va_end (arglist);

      const TCHAR *mesg[] = { msg[0], msg[1] };
      ReportEvent (hEventSource, flags & MSG_FLAGS_ERROR ?
                   EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
                   0, 0, NULL, 2, 0, mesg, NULL);
      DeregisterEventSource (hEventSource);
    }

  return error;
}
开发者ID:746bce42110a11028656eca33867,项目名称:openvpn,代码行数:35,代码来源:common.c


示例20: AddToMessageLog

static VOID AddToMessageLog(LPCTSTR lpszMsg)
{
	HANDLE hEventSource = NULL;
	LPTSTR lpszStrings[2];
	TCHAR szMsg[512] = _T("");
	TCHAR szErrMsg[2048] = _T("");

	if (!bDebug) {
		dwErr = GetLastError();

		GetLastErrorText(szErr, CountOf(szErr));

		_stprintf(szMsg, _T("%s error: %d"), szServiceName, dwErr);
		_stprintf(szErrMsg, _T("{%s}: %s"), lpszMsg, szErr);

		lpszStrings[0] = szMsg;
		lpszStrings[1] = szErrMsg;

		if ((hEventSource = RegisterEventSource(NULL, szServiceName)) != NULL) {
			ReportEvent(hEventSource,	// handle of event source
				    EVENTLOG_ERROR_TYPE,	// event type
				    0,	// event category
				    0,	// event ID
				    NULL,	// current user's SID
				    2,	// strings in lpszStrings
				    0,	// no bytes of raw data
				    (const char **) lpszStrings,	// array of error strings
				    NULL);	// no raw data

			DeregisterEventSource(hEventSource);
		}
	}

}
开发者ID:linkclau,项目名称:XMail,代码行数:34,代码来源:MainWin.cpp



注:本文中的GetLastErrorText函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetLastPosition函数代码示例发布时间:2022-05-30
下一篇:
C++ GetLanguageDescByID函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap