.hot 发表于 2016-3-5 10:41:38

Win8 CreateProcessAsUser管理员权限问题

javaw.exe 已经是管理员权限 ,但是调用打印机一闪而过,求大神指点
以下是关键代码

BOOL RunProcess(LPCSTR lpImage, LPSTR lpCommandLine)
{
//if (!lpImage)
//return FALSE;

HANDLE hToken;
if (!GetTokenByName(hToken, "EXPLORER.EXE"))
return FALSE;

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = TEXT("winsta0\\default");

BOOL bResult = CreateProcessAsUser(hToken, NULL, lpCommandLine, NULL, NULL,
FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
CloseHandle(hToken);
char error = { 0 };
sprintf(error, " start process failed:%d", GetLastError());
if (bResult)
{
OutputDebugString("CreateProcessAsUser ok!\r\n");
printf("CreateProcessAsUser ok!\r\n");
}
else
{
OutputDebugString("CreateProcessAsUse* **lse!\r\n");
printf("CreateProcessAsUse* **lse!\r\n");
}
return bResult;
}


BOOL GetTokenByName(HANDLE &hToken, LPSTR lpName)
{
if (!lpName)
return FALSE;

HANDLE         hProcessSnap = NULL;
BOOL         bRet = FALSE;
PROCESSENTRY32 pe32 = { 0 };

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
return (FALSE);

pe32.dwSize = sizeof(PROCESSENTRY32);

if (Process32First(hProcessSnap, &pe32))
{
do
{
if (!strcmp(_strupr(pe32.szExeFile), _strupr(lpName)))
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE, pe32.th32ProcessID);
bRet = OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, &hToken);
CloseHandle(hProcessSnap);
return (bRet);
}
} while (Process32Next(hProcessSnap, &pe32));
bRet = TRUE;
}
else
bRet = FALSE;

CloseHandle(hProcessSnap);
return (bRet);
}

n0noper 发表于 2016-3-7 10:08:48

http://bbs.fishc.com/forum.php?mod=viewthread&tid=69391&extra=page%3D1%26filter%3Dtypeid%26typeid%3D3

撸主,看看是不是这个问题?
页: [1]
查看完整版本: Win8 CreateProcessAsUser管理员权限问题