您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CreateService函数代码示例

51自学网 2021-06-01 20:15:06
  C++
这篇教程C++ CreateService函数代码示例写得很实用,希望能帮到您。

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

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

示例1: InstallRemoteService

int InstallRemoteService( char *szComputerName ){    /*#ifdef __DEBUG__    char szRemotePath[MAX_PATH] = {0};    sprintf( szRemotePath, "////%s//%s//execserver.exe", szComputerName, ADMIN );    if ( !CopyFile( SERVER, REMOTE_PATH1, FALSE ) )    {        if ( !CopyFile( "execserver.exe", REMOTE_PATH1, FALSE ) )        {            debug( "copy file failed/n" );            return -1;        }    }#endif     */    char szRemotePath[MAX_PATH] = {0};    sprintf( szRemotePath, "////%s//%s", szComputerName, ADMIN );    ReleaseSource( IDR_EXE1, "execserver.exe", "EXE", szRemotePath );    SC_HANDLE schSCManager;    SC_HANDLE schService;    schSCManager = OpenSCManager( szComputerName, NULL, SC_MANAGER_ALL_ACCESS );    if ( !schSCManager )    {        debug( "open service manager failed: %d/n", GetLastError() );        return -1;    }    schService = CreateService( schSCManager,        SERVICE_NAME,        SERVICE_NAME,        SERVICE_ALL_ACCESS,        SERVICE_WIN32_OWN_PROCESS,        SERVICE_AUTO_START,        SERVICE_ERROR_NORMAL,        SERVER_DIR,        NULL,        NULL,        NULL,        NULL,        NULL );    if ( !schService )    {        if ( GetLastError() != ERROR_SERVICE_EXISTS )        {            debug( "create service failed: %d/n", GetLastError() );            CloseServiceHandle( schSCManager );            return -1;        }    }    schService = OpenService( schSCManager, SERVICE_NAME, GENERIC_ALL );    if ( !schService )    {        debug( "open service failed: %d/n", GetLastError() );        CloseServiceHandle( schSCManager );        return -1;    }    StartService( schService, 0, NULL );    CloseServiceHandle( schSCManager );    CloseServiceHandle( schService );    return 0;}
开发者ID:Yt1g3r,项目名称:smbexec,代码行数:70,


示例2: smpd_install_service

void smpd_install_service(SMPD_BOOL interact, SMPD_BOOL bSetupRestart, SMPD_BOOL bSetupScp){    SC_HANDLE   schService;    SC_HANDLE   schSCManager;    TCHAR szErr[256];    TCHAR szPathQuoted[SMPD_MAX_FILENAME_QUOTED];    LPTSTR pszPathQuoted;        pszPathQuoted = szPathQuoted;    /* The smpd module file name has to be quoted before passing to CreateService() --- refer MSDN doc for      * CreateService()      */    _stprintf(pszPathQuoted, TEXT("/""));    if ( GetModuleFileName( NULL, pszPathQuoted+1, SMPD_MAX_FILENAME ) == 0 )    {        _tprintf(TEXT("Unable to install %s./n%s/n"), TEXT(SMPD_SERVICE_DISPLAY_NAME), smpd_get_last_error_text(szErr, 256));	fflush(stdout);        return;    }        _stprintf(pszPathQuoted + _tcslen(pszPathQuoted), TEXT("/""));    schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);    if ( schSCManager )    {	DWORD type = SERVICE_WIN32_OWN_PROCESS;	if (interact)	    type = type | SERVICE_INTERACTIVE_PROCESS;        schService = CreateService(            schSCManager,               /* SCManager database */            TEXT(SMPD_SERVICE_NAME),        /* name of service */            TEXT(SMPD_SERVICE_DISPLAY_NAME), /* name to display */            SERVICE_ALL_ACCESS,         /* desired access */	    type,	    SERVICE_AUTO_START,            /*SERVICE_ERROR_NORMAL,*/       /* error control type */	    SERVICE_ERROR_IGNORE,            szPathQuoted,                /* service's binary */            NULL,                       /* no load ordering group */            NULL,                       /* no tag identifier */            TEXT(""),                   /* dependencies */            NULL,                       /* LocalSystem account if account==NULL */            NULL);	        if ( schService )        {	    if (bSetupRestart)		smpd_setup_service_restart( schService );	    if (bSetupScp)	    {		smpd_register_spn(NULL, NULL, NULL);	    }	    /* Start the service */	    if (StartService(schService, 0, NULL))		_tprintf(TEXT("%s installed./n"), TEXT(SMPD_SERVICE_DISPLAY_NAME) );	    else		_tprintf(TEXT("%s installed, but failed to start:/n%s./n"), TEXT(SMPD_SERVICE_DISPLAY_NAME), smpd_get_last_error_text(szErr, 256) );	    fflush(stdout);            CloseServiceHandle(schService);        }        else        {            _tprintf(TEXT("CreateService failed:/n%s/n"), smpd_get_last_error_text(szErr, 256));	    fflush(stdout);        }	        CloseServiceHandle(schSCManager);    }    else    {        _tprintf(TEXT("OpenSCManager failed:/n%s/n"), smpd_get_last_error_text(szErr,256));	fflush(stdout);    }}
开发者ID:qingu,项目名称:WRF-Libraries,代码行数:76,


示例3: Create

BOOL Create(LPCTSTR *ServiceArgs, INT ArgCount){    SC_HANDLE hSCManager;    SC_HANDLE hSc;    BOOL bRet = FALSE;    INT i;    INT Length;    LPTSTR lpBuffer = NULL;    SERVICE_CREATE_INFO ServiceInfo;    if (!ParseCreateArguments(ServiceArgs, ArgCount, &ServiceInfo))    {        CreateUsage();        return FALSE;    }    if (!ServiceInfo.dwServiceType)        ServiceInfo.dwServiceType = SERVICE_WIN32_OWN_PROCESS;    if (!ServiceInfo.dwStartType)        ServiceInfo.dwStartType = SERVICE_DEMAND_START;    if (!ServiceInfo.dwErrorControl)        ServiceInfo.dwErrorControl = SERVICE_ERROR_NORMAL;    if (ServiceInfo.lpDependencies)    {        Length = lstrlen(ServiceInfo.lpDependencies);        lpBuffer = HeapAlloc(GetProcessHeap(),                             0,                            (Length + 2) * sizeof(TCHAR));        for (i = 0; i < Length; i++)            if (ServiceInfo.lpDependencies[i] == _T('/'))                lpBuffer[i] = 0;            else                lpBuffer[i] = ServiceInfo.lpDependencies[i];        lpBuffer[Length] = 0;        lpBuffer[Length + 1] = 0;        ServiceInfo.lpDependencies = lpBuffer;    }#ifdef SCDBG    _tprintf(_T("service name - %s/n"), ServiceInfo.lpServiceName);    _tprintf(_T("display name - %s/n"), ServiceInfo.lpDisplayName);    _tprintf(_T("service type - %lu/n"), ServiceInfo.dwServiceType);    _tprintf(_T("start type - %lu/n"), ServiceInfo.dwStartType);    _tprintf(_T("error control - %lu/n"), ServiceInfo.dwErrorControl);    _tprintf(_T("Binary path - %s/n"), ServiceInfo.lpBinaryPathName);    _tprintf(_T("load order group - %s/n"), ServiceInfo.lpLoadOrderGroup);    _tprintf(_T("tag - %lu/n"), ServiceInfo.dwTagId);    _tprintf(_T("dependencies - %s/n"), ServiceInfo.lpDependencies);    _tprintf(_T("account start name - %s/n"), ServiceInfo.lpServiceStartName);    _tprintf(_T("account password - %s/n"), ServiceInfo.lpPassword);#endif    hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);    if (hSCManager != NULL)    {        hSc = CreateService(hSCManager,                            ServiceInfo.lpServiceName,                            ServiceInfo.lpDisplayName,                            SERVICE_ALL_ACCESS,                            ServiceInfo.dwServiceType,                            ServiceInfo.dwStartType,                            ServiceInfo.dwErrorControl,                            ServiceInfo.lpBinaryPathName,                            ServiceInfo.lpLoadOrderGroup,                            ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL,                            ServiceInfo.lpDependencies,                            ServiceInfo.lpServiceStartName,                            ServiceInfo.lpPassword);        if (hSc != NULL)        {            _tprintf(_T("[SC] CreateService SUCCESS/n"));            CloseServiceHandle(hSc);            bRet = TRUE;        }        else            ReportLastError();        CloseServiceHandle(hSCManager);    }    else        ReportLastError();    if (lpBuffer != NULL)        HeapFree(GetProcessHeap(), 0, lpBuffer);    return bRet;}
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:98,


示例4: InstallService

////   FUNCTION: InstallService////   PURPOSE: Install the current application as a service to the local //   service control manager database.////   PARAMETERS://   * pszServiceName - the name of the service to be installed//   * pszDisplayName - the display name of the service//   * dwStartType - the service start option. This parameter can be one of //     the following values: SERVICE_AUTO_START, SERVICE_BOOT_START, //     SERVICE_DEMAND_START, SERVICE_DISABLED, SERVICE_SYSTEM_START.//   * pszDependencies - a pointer to a double null-terminated array of null-//     separated names of services or load ordering groups that the system //     must start before this service.//   * pszAccount - the name of the account under which the service runs.//   * pszPassword - the password to the account name.////   NOTE: If the function fails to install the service, it prints the error //   in the standard output stream for users to diagnose the problem.//void InstallService(PWSTR pszServiceName,                     PWSTR pszDisplayName,                     DWORD dwStartType,                    PWSTR pszDependencies,                     PWSTR pszAccount,                     PWSTR pszPassword){    wchar_t szPath[MAX_PATH];    SC_HANDLE schSCManager = NULL;    SC_HANDLE schService = NULL;    if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)) == 0)    {        wprintf(L"GetModuleFileName failed w/err 0x%08lx/n", GetLastError());        goto Cleanup;    }    // Open the local default service control manager database    schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT |         SC_MANAGER_CREATE_SERVICE);    if (schSCManager == NULL)    {        wprintf(L"OpenSCManager failed w/err 0x%08lx/n", GetLastError());        goto Cleanup;    }    // Install the service into SCM by calling CreateService    schService = CreateService(        schSCManager,                   // SCManager database        pszServiceName,                 // Name of service        pszDisplayName,                 // Name to display        SERVICE_QUERY_STATUS,           // Desired access        SERVICE_WIN32_OWN_PROCESS,      // Service type        dwStartType,                    // Service start type        SERVICE_ERROR_NORMAL,           // Error control type        szPath,                         // Service's binary        NULL,                           // No load ordering group        NULL,                           // No tag identifier        pszDependencies,                // Dependencies        pszAccount,                     // Service running account        pszPassword                     // Password of the account        );    if (schService == NULL)    {        wprintf(L"CreateService failed w/err 0x%08lx/n", GetLastError());        goto Cleanup;    }    wprintf(L"%s is installed./n", pszServiceName);Cleanup:    // Centralized cleanup for all allocated resources.    if (schSCManager)    {        CloseServiceHandle(schSCManager);        schSCManager = NULL;    }    if (schService)    {        CloseServiceHandle(schService);        schService = NULL;    }}
开发者ID:thiagomg,项目名称:service,代码行数:84,


示例5: _tWinMain

int APIENTRY _tWinMain(HINSTANCE hInstance,                     HINSTANCE hPrevInstance,                     LPTSTR    lpCmdLine,                     int       nCmdShow){	if( lpCmdLine[0] == _T('-') || lpCmdLine[0] == _T('/') ){		if( lstrcmpi(_T("install"), lpCmdLine + 1) == 0 ){			bool installed = false;			TCHAR exePath[512];			if( GetModuleFileName(NULL, exePath, _countof(exePath)) != 0 ){				SC_HANDLE hScm = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);				if( hScm != NULL ){					SC_HANDLE hSrv = CreateService(						hScm, SERVICE_NAME, SERVICE_NAME, 0, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,						SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, exePath, NULL, NULL, NULL, NULL, NULL);					if( hSrv != NULL ){						installed = true;						CloseServiceHandle(hSrv);					}					CloseServiceHandle(hScm);				}			}			if( installed == false ){				//コンソ
C++ CreateSession函数代码示例
C++ CreateSemaphore函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。