调用Exe程序并且出现界面 CreateProc(ProcessName:String)

Function GetProcessHandleAsName(Name:String):THandle;
Var
Hd,Hs:THandle;
dExit:Cardinal;
Tmp,Tmp1:String;
Lp:TProcessEntry32;
begin
Result:=0;
Lp.dwSize:=sizeof(TProcessEntry32);
Hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if Process32First(Hd,Lp) then
Repeat
Tmp:=UpperCase(Trim(Name));
Tmp1:=Trim(UpperCase(Lp.szExeFile));
if AnsiPos(Tmp,Tmp1)>0 then
begin
Result:=OpenProcess(PROCESS_ALL_ACCESS,true,Lp.th32ProcessID);
break;
end
Until Process32Next(Hd,Lp)=False;
end;

procedure CreateProc(ProcessName:String);
Var
siStartupInfo:STARTUPINFO;
saProcess,saThread:SECURITY_ATTRIBUTES;
piProcInfo:PROCESS_INFORMATION;
Hd:Cardinal;
ProcessHd:THandle;
Hds:THandle;
Str:String;
begin
ProcessHd:=GetProcessHandleAsName('Explorer');
if ProcessHd=0 then
Exit;
if OpenProcessToken(ProcessHd,TOKEN_ALL_ACCESS,Hds) then
if DuplicateTokenEx(Hds,TOKEN_ALL_ACCESS,nil,SecurityIdentification,TokenPrimary,Hd) then
begin
ZeroMemory(@siStartupInfo,sizeof(siStartupInfo));
siStartupInfo.cb:=sizeof(siStartupInfo);
saProcess.nLength:=sizeof(saProcess);
saProcess.lpSecurityDescriptor:=nil;
saProcess.bInheritHandle:=false;
saThread.nLength:=sizeof(saThread);
saThread.lpSecurityDescriptor:=nil;
saThread.bInheritHandle:=false;
CreateProcessAsUser(Hd,nil,PChar(ProcessName),nil,nil,false,
CREATE_DEFAULT_ERROR_MODE,nil,nil,siStartupInfo,piProcInfo);
end;
end;
posted @ 2024-11-15 10:18  南国之恋  阅读(4)  评论(0编辑  收藏  举报