从Windows 7中的Windows服务运行DLL / EXE程序

时间:2013-12-17 10:13:42

标签: c# c++ .net windows dll

我实际上需要一个专家建议来解决在Windows 7中调用InitPK.dll(C ++ dll)作为服务的情况(附带代码)。 dll成功加载,但PKAgentInit方法在Windows 7上使用Windows服务返回0(false)同样在Windows XP中工作正常,当exec作为Windows 7上的控制台程序时,代码工作正常。 您能否指导我们为什么PKAgentInit方法在Windows 7上返回0,以及在Windows 7下使用Windows服务调用Agent的推荐方法是什么。**

代码:

typedef UINT (CALLBACK* INITPK)();    
m_LogDebug->Log(2,nThreadId,cMethod, 
  "Pre-requisite applications are running so executing Agent...");            
hDll = LoadLibrary(AgentPath.c_str());    
if(hDll == NULL)    
{    
    m_LogDebug->Log(0,nThreadId,cMethod,
      "Failed to load     [%s]",AgentPath.c_str());    
    return false;    
}    
INITPK InitPK_Func;    
if((InitPK_Func = (INITPK)GetProcAddress(HMODULE(hDll), "PKAgentInit")) == NULL)
{    
    m_LogDebug->Log(0,nThreadId,cMethod,
      "Failed to load proc address [%s]",AgentPath.c_str());    
    return false;    
}    
UINT Res = InitPK_Func();             
// returning 0 which means Agent is not executed successfully. 
// Ideally it should return 1.    
m_LogDebug->Log(0,nThreadId,cMethod,"PKAgentInit returned [%d]",Res);    

1 个答案:

答案 0 :(得分:0)

没有看到InitPK_Func()的来源,很难说,但我猜这是一个特权问题,并且该服务没有以可以做您需要做的事情的用户身份运行。也许有问题的代码需要提升(可能是它在XP上运行的原因),或者它可能触及网络资源(可能是它在Win7上作为控制台应用程序工作的原因)。

但实际上,您需要调试问题函数,并可能更改它以返回有关失败原因的更多信息。

相关问题