|
5精币
那位大神可以把 CreateProcessAsUser 封装到火山PC一下下,谢谢了先
这里有C++源码
// pch.cpp: 与预编译标头对应的源文件;编译成功所必需的
#include "pch.h"
#include <windows.h>
#include <stdio.h>
#include <userenv.h>
#include <iostream>
#include <Wtsapi32.h>
#pragma comment(lib, "Wtsapi32.lib")
#pragma comment(lib, "Userenv.lib")
#include<tchar.h>
#include <atlconv.h>
#include <tlhelp32.h>
void main(int argc, WCHAR *argv[])
{
//BOOL CreateProcessAsUser(
//HANDLE hToken,//处理表示登录用户的标记
//LPCTSTR lpApplicationName,//指向可执行模块名称的指针
//LPTSTR lpCommandLine,//指向命令行字符串的指针
//LPSECURITY_ATTRIBUTES lpProcessAttributes,//处理安全属性
//LPSECURITY_ATTRIBUTES lpThreadAttributes, //线程安全属性
//BOOL bInheritHandles,//新进程是否继承处理
//DWORD dwCreationFlags,//创建标志
//LPVOID lpEnvironment,//指向新环境块的
//指针LPCTSTR lpCurrentDirectory,//指向当前目录名称的
//指针LPSTARTUPINFO lpStartupInfo,//指向STARTUPINFO的指针
//LPPROCESS_INFORMATION lpProcessInformation //指向PROCESS_INFORMATION的指针
//);
HANDLE hToken = NULL;
BOOL bResult = FALSE;
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));//清空内存
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = L"winsta0\\default";
LPVOID environment;
BOOL blockRet = CreateEnvironmentBlock(&environment, hToken, FALSE);
if (!blockRet)
{
printf("could not create environment block (error: %i)",GetLastError());
}
else
{
TCHAR Cmdline[MAX_PATH] = _T("C:\\Windows\\system32\\notepad.exe");
DWORD creationFlags = NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT;
bResult = CreateProcessAsUser(
hToken,
NULL,
Cmdline,
NULL,
NULL,
FALSE,
creationFlags,
environment,
NULL,
&si,
&pi
);
if (bResult)
{
printf("CreateProcessAsUser成功 = %d", bResult);
}
else
{
printf("CreateProcessAsUser失败 = %d", GetLastError());
}
// close the handles
if (bResult && pi.hProcess != INVALID_HANDLE_VALUE)
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
}
else
{
printf("CreateProcessAsUser1 = %d", GetLastError());
}
if (pi.hThread != INVALID_HANDLE_VALUE)
CloseHandle(pi.hThread);
DestroyEnvironmentBlock(environment);
}
RevertToSelf();
CloseHandle(hToken);
}
|
|