Windows CreateProcessWithLogonW错误1783:存根接收到错误数据
我有这个测试代码:Windows CreateProcessWithLogonW错误1783:存根接收到错误数据,windows,winapi,createprocess,createprocessasuser,Windows,Winapi,Createprocess,Createprocessasuser,我有这个测试代码: int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); std::string user; std::string pass; std::cout << "user: "; getline(std::cin, user); std::cout << "\npass: "; getline(std::cin, pass); std
int main(int argc, char *argv[])
{
setlocale(LC_ALL, "");
std::string user;
std::string pass;
std::cout << "user: ";
getline(std::cin, user);
std::cout << "\npass: ";
getline(std::cin, pass);
std::cout << std::endl;
std::wstring suser = std::wstring(user.begin(), user.end());
LPCWSTR su = suser.c_str();
std::wstring spass = std::wstring(pass.begin(), pass.end());
LPCWSTR sp = spass.c_str();
DWORD dwSize = 0;
HANDLE hToken ;
LPVOID lpvEnv = 0;
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
WCHAR szUserProfile[256] = L"";
si.cb = sizeof(STARTUPINFO);
if (!LogonUser(su, L".", sp, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, &hToken))
qDebug() << "LogonUser";
if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE))
qDebug() << "CreateEnvironmentBlock";
dwSize = sizeof(szUserProfile)/sizeof(WCHAR);
if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize))
qDebug() << "GetUserProfileDirectory";
WCHAR app[] = L"\"C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe\" \"C:\\Users\\UD\\Desktop\\insect immunity.pdf\"";
if (!CreateProcessWithLogonW(su, L".", sp,
LOGON_WITH_PROFILE, NULL, app,
CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile,
&si, &pi)) {
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("failed with error %d: %s"), dw, lpMsgBuf);
qDebug() << QString::fromWCharArray((LPTSTR)lpDisplayBuf);
}
if (!DestroyEnvironmentBlock(lpvEnv))
qDebug() << "DestroyEnvironmentBlock";
CloseHandle(hToken);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
system("pause");
return 0;
}
在我朋友的电脑上,它总是很好用。在我的电脑上,它有时工作!只是有时候,大多数时候它会产生1783错误。我试图删除我电脑上的一些服务,但没有帮助。我需要该代码在许多其他PC上工作,所以我需要了解为什么会出现此错误以及如何修复它 有助于在CreateProcessWithLogonW中将Environment设置为NULL/我的解决方案: 以前,我从guest帐户调用它来启动系统帐户中的进程。如果需要,我让应用程序弹出一个对话框来接收凭据,并在函数CreateProcessWithLogonW中使用相同的凭据,但失败了,错误代码为1783 解决方案:现在,在收到错误代码后,我弹出一个UAC对话框,用户必须在其中输入凭据,而不是应用程序处理凭据,然后它就会工作
看起来像是权限问题。不管怎样,这对我的用例是有效的,如果有人的也遵循同样的思路,这可能会有所帮助 为什么要同时使用LogonUser和CreateProcessWithLogonW?通过使用LogonUser,您已经拥有了用户的令牌,因此您应该改用CreateProcessAsUser。它是MS examaple,而不是mainHi,我面临着同样的问题。如果你已经解决了这个问题,你是如何解决的?