ERROR_INVALID_ADDRESS (0x000001e7)

0

plz help me this problem:

I create a basic service in this code:

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

I think I initialized my variables, why i still got this error: When I run it, I get error: CreateService failed w/err 0x000001e7 (I only know it is: ERROR_INVALID_ADDRESS) - but I don't known what is exactly mean, and how to fix.

Anyone plz help me.

c++
winapi
service
asked on Stack Overflow Nov 15, 2013 by cristiano

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0