我写了一个程序,应该像RunAs一样工作。它工作正常,但我有一个问题。如果我想运行例如compmgmt.msc,那么我应该运行mmc.exe和compmgmt.msc作为它的参数。计算机管理将打开,但不会在用户之下,因为我想运行它。它将在登录的用户名下运行。有人可以告诉我为什么会这样,我该如何纠正它?这是我的代码:
void createproc(
wchar_t * user,
wchar_t * domain,
wchar_t * pass,
wchar_t * applicationname)
{
int errorcode;
char cmd[Buf_Size];
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcInfo;
memset(&ProcInfo, 0, sizeof(ProcInfo));
memset(&StartInfo, 0 , sizeof(StartInfo));
StartInfo.cb = sizeof(StartInfo);
StartInfo.wShowWindow = SW_HIDE;
int bFuncRetn =
CreateProcessWithLogonW
(
user,
domain,
pass,
LOGON_NETCREDENTIALS_ONLY,
L"C:\\Windows\\System32\\mmc.exe", //applicationname,
L" compmgmt.msc",
CREATE_UNICODE_ENVIRONMENT,
NULL,
NULL,
(LPSTARTUPINFOW)&StartInfo,
&ProcInfo
);
errorcode = GetLastError();
if ( bFuncRetn == 0 )
{
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
printf("\nGetLastError :: %d CreateProcessWithLogonW Failed!",
errorcode);
printf("\nFor more information type :: Net Helpmsg %d",
errorcode);
getch();
exit(1);
}
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
}//createproc
感谢您的帮助!
kampi
答案 0 :(得分:1)