ERROR_INVALID_ADDRESS(0x000001e7)

时间:2013-11-15 04:39:45

标签: c++ winapi service

PLZ帮我解决这个问题:

我在此代码中创建了一个基本服务:

#include "stdafx.h"

PWSTR pszServiceName;
PWSTR pszDisplayName; 
DWORD dwStartType;
PWSTR pszDependencies; 
PWSTR pszAccount;
PWSTR pszPassword;

void __cdecl _tmain(int argc, TCHAR *argv[]) 
{ 
    lstrcpyW(pszServiceName, L"Win32_Service");
    lstrcpyW(pszDisplayName, L"My Service"); 
    dwStartType = SERVICE_DEMAND_START;
    lstrcpyW(pszDependencies,L""); 
    lstrcpyW(pszAccount, L"NT AUTHORITY\\LocalService");
    pszPassword = NULL;

    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;
    }
} 

我想我初始化了我的变量,为什么我仍然遇到这个错误: 当我运行它时,我得到错误:CreateService失败w / err 0x000001e7(我只知道它是:ERROR_INVALID_ADDRESS) - 但我不知道究竟是什么意思,以及如何修复。

任何人都帮助我。

0 个答案:

没有答案