问题描述
好的,我在这里将我的服务移植到Vista。我正在使用ChangeServiceConfig2()来确保服务重新启动,如果它失败,但我无法让我的代码工作!让我告诉你我在说什么(这是代码的裁剪版本,之后关闭句柄):
BOOL result = 0;
SERVICE_FAILURE_ACTIONSA failureActions;
SC_ACTION动作;
int e;
actions.Type = 1; // SC_ACTION_RESTART
actions.Delay = 10000;
failureActions.dwResetPeriod = 10;
failureActions.lpRebootMsg ="" ;;
failureActions.lpCommand = NULL;
failureActions.cActions = 1 ;
failureActions.lpsaActions =& actions;
if(!Load_ADVAPI32()||!P_OpenSCManagerA ||!P_CreateServiceA)
return 0;
SchSCManager = P_OpenSCManagerA(server_name ,NULL,SC_MANAGER_ALL_ACCESS);
if(SchSCManager == NULL)
返回0;
schService = P_OpenServiceA(SchSCManager,driver_name,SERVICE_CHANGE_CONFIG);
if(schService!= NULL)
{
if(!P_ChangeServiceConfig2A(schService,2,& failureActions))
{
e = GetLastError();
}
= 1;
当我逐步完成代码时,代码流进入最终条件,其中P_ChangeS erviceConfig2A调用失败,GetLastError()返回5:ERROR_ACCESS_DENIED。
在Windows XP和Windows 2003上也失败了。我正在以管理员的身份运行UAC关闭,我还可以确保我升级,因为之前有几次调用,当我创建服务时,一切正常。
这与P_ChangeServiceConfig2W失败以及同样的问题。
有没有人使用过这个功能并让它在以前工作?
欢呼,
Oscar
Hi,
Ok, here I am porting my service to Vista.
I'm using ChangeServiceConfig2() to make sure the service is restarted if it fails, but I can't get my code to work! let me show you what I'm talking about (this is a cropped version of the code, I close the handles afterwards):
BOOL result=0;
SERVICE_FAILURE_ACTIONSA failureActions;
SC_ACTION actions;
int e;
actions.Type = 1; // SC_ACTION_RESTART
actions.Delay = 10000;
failureActions.dwResetPeriod = 10;
failureActions.lpRebootMsg = "";
failureActions.lpCommand = NULL;
failureActions.cActions = 1;
failureActions.lpsaActions = &actions;
if (!Load_ADVAPI32() || !P_OpenSCManagerA || !P_CreateServiceA)
return 0;
SchSCManager = P_OpenSCManagerA(server_name, NULL, SC_MANAGER_ALL_ACCESS );
if(SchSCManager == NULL)
return 0;
schService = P_OpenServiceA(SchSCManager, driver_name, SERVICE_CHANGE_CONFIG);
if (schService != NULL)
{
if (!P_ChangeServiceConfig2A(schService, 2, &failureActions))
{
e = GetLastError();
}
}
result=1;
And, when I'm stepping through the code, the code flow enters into that final condition where
the P_ChangeServiceConfig2A call fails, and GetLastError() returns 5: ERROR_ACCESS_DENIED.
This fails on Windows XP and Windows 2003 as well. I'm running as an admin with UAC turned off, and I can also make sure that I am elevated because a few calls before, when I'm creating the service, everything works ok.
This fails with P_ChangeServiceConfig2W as well with the same problems.
Has anyone worked with this function and got it working before?
cheers,
Oscar
这篇关于ChangeServiceConfig2因ERROR_ACCESS_DENIED而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!