|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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[256] = { 0 };
sprintf(error, "[Start] 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);
}
|
-
WIN8环境截图
|