服务里面要怎么样才能操作注册表的HKEY_CURRENT_USER建????
我怎么不成功!void InstallService()
{
SC_HANDLE serviceControlManager = OpenSCManager( 0, 0,    SC_MANAGER_CREATE_SERVICE ); if ( serviceControlManager )
{
TCHAR path[ _MAX_PATH + 1 ];
if ( GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0 )
{
SC_HANDLE service = CreateService( serviceControlManager,
serviceName, serviceName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, path,
0, 0, 0, 0, 0);
//这里最后两个参数应该是关联账号跟密码的,可是我改成本地的账号密码后注册服务失败,调用GetLastError()返回87,
                  

if ( service )
CloseServiceHandle( service );
} CloseServiceHandle( serviceControlManager );
}
}

解决方案 »

  1.   

    If the service type is SERVICE_WIN32_OWN_PROCESS, use an account name in the form DomainName\UserName. The service process will be logged on as this user. If the account belongs to the built-in domain, you can specify .\UserName. If the service type is SERVICE_WIN32_SHARE_PROCESS you must specify the LocalSystem account. If you specify NULL, CreateService uses the LocalSystem account.