您可以尝试使用模拟。像这样的东西...
wchar_t* cmPath=readRegistryString(L"Software\\" TO_WCHAR(ORG_NAME) L"\\" TO_WCHAR(APP_NAME) L"\\" TO_WCHAR(APPLICATION_GROUP),TO_WCHAR(APPLICATION_EXEC_PATH));
if (!cmPath)
{
return false;
}
HANDLE userToken=NULL;
DWORD sessId=WTSGetActiveConsoleSessionId ();
if((long)sessId==-1)
{
sessId=0;
}
WTSQueryUserToken (sessId, &userToken);
bool result=false;
if(userToken/**/ )
{
SECURITY_ATTRIBUTES sa;
ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
STARTUPINFOW si;
ZeroMemory(&si,sizeof(STARTUPINFOW));
si.cb=sizeof(STARTUPINFOW);
PROCESS_INFORMATION pi;
ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
CStringW str= L"\"";
str=str+cmPath;
str=str+L"\"";
str.Replace(L"/",L"\\");
if(CreateProcessAsUserW(userToken,NULL,str.GetBuffer(),NULL,NULL,false,NULL,NULL,NULL,&si,&pi))
{
result=true;
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else
{
DWORD err = GetLastError();
//nop;
}
}
if(userToken)
CloseHandle(userToken);
delete[] cmPath;
这段代码我用来从服务中调用 GUI 应用程序,但我认为控制台应用程序不需要太多更改。