{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;
Function CreateProc(ProcessName:String):boolean;
Var
siStartupInfo:STARTUPINFO;
saProcess,saThread:SECURITY_ATTRIBUTES;
piProcInfo:PROCESS_INFORMATION;
Hd:NativeInt;
ProcessHd:THandle;
Hds:THandle;
Str:String;
begin
Result := false;
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;
if CreateProcessAsUser(Hd,nil,PChar(ProcessName),nil,nil,false,
CREATE_DEFAULT_ERROR_MODE,nil,nil,siStartupInfo,piProcInfo) then
Result := true;
end;
end;}
if DuplicateTokenEx(Hds,TOKEN_ALL_ACCESS,nil,SecurityIdentification,TokenPrimary,hd) then
[dcc32 Error] Unit1.pas(113): E2033 Types of actual and formal var parameters must be identical
function RunProcess(const ProcessName: String): Boolean;
function CheckProcessHd(const aFileName: string): THandle;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
Found: Boolean;
begin
Result := 0;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
lppe.dwSize := sizeof(TProcessEntry32);
Found := Process32First(hSnapshot, lppe);
while Found do
begin
if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(aFileName)) or
(UpperCase(lppe.szExeFile) = UpperCase(aFileName))) then
begin
Result := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
CloseHandle(hSnapshot);
Exit;
end;
Found := Process32Next(hSnapshot, lppe);
end;
CloseHandle(hSnapshot);
end;
Var
siStartupInfo: STARTUPINFO;
saProcess, saThread: SECURITY_ATTRIBUTES;
piProcInfo: PROCESS_INFORMATION;
// Hd: Cardinal;
HD: THandle;
ProcessHd: THandle;
Hds: THandle;
// Str: String;
begin
Result := False;
if not FileExists(ProcessName) then
begin
Exit;
end;
ProcessHd := CheckProcessHd('explorer.exe');
if ProcessHd = 0 then
Exit;
if OpenProcessToken(ProcessHd, TOKEN_ALL_ACCESS, Hds) then
begin
{ if DuplicateTokenEx(Hds, TOKEN_ALL_ACCESS, nil, SecurityIdentification,
TokenPrimary, Hd) 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;
Result := CreateProcessAsUser(HD, nil, PChar(ProcessName), nil, nil,
False, CREATE_DEFAULT_ERROR_MODE, nil, nil, siStartupInfo, piProcInfo);
end;
end;
end;
function RunProcess(const ProcessName: String): Boolean;
function CheckProcessHd(const aFileName: string): THandle;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
Found: Boolean;
begin
Result := 0;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
lppe.dwSize := sizeof(TProcessEntry32);
Found := Process32First(hSnapshot, lppe);
while Found do
begin
if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(aFileName)) or
(UpperCase(lppe.szExeFile) = UpperCase(aFileName))) then
begin
Result := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
CloseHandle(hSnapshot);
Exit;
end;
Found := Process32Next(hSnapshot, lppe);
end;
CloseHandle(hSnapshot);
end;
Var
siStartupInfo: STARTUPINFO;
saProcess, saThread: SECURITY_ATTRIBUTES;
piProcInfo: PROCESS_INFORMATION;
// Hd: Cardinal;
HD: THandle;
ProcessHd: THandle;
Hds: THandle;
// Str: String;
begin
Result := False;
if not FileExists(ProcessName) then
begin
Exit;
end;
ProcessHd := CheckProcessHd('explorer.exe');
if ProcessHd = 0 then
Exit;
if OpenProcessToken(ProcessHd, TOKEN_ALL_ACCESS, Hds) then
begin
{ if DuplicateTokenEx(Hds, TOKEN_ALL_ACCESS, nil, SecurityIdentification,
TokenPrimary, Hd) 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;
Result := CreateProcessAsUser(HD, nil, PChar(ProcessName), nil, nil,
False, CREATE_DEFAULT_ERROR_MODE, nil, nil, siStartupInfo, piProcInfo);
end;
end;
end;
function RunProcess(const ProcessName: String): Boolean;
function CheckProcessHd(const aFileName: string): THandle;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
Found: Boolean;
begin
Result := 0;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
lppe.dwSize := sizeof(TProcessEntry32);
Found := Process32First(hSnapshot, lppe);
while Found do
begin
if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(aFileName)) or
(UpperCase(lppe.szExeFile) = UpperCase(aFileName))) then
begin
Result := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
CloseHandle(hSnapshot);
Exit;
end;
Found := Process32Next(hSnapshot, lppe);
end;
CloseHandle(hSnapshot);
end;
Var
siStartupInfo: STARTUPINFO;
saProcess, saThread: SECURITY_ATTRIBUTES;
piProcInfo: PROCESS_INFORMATION;
// Hd: Cardinal;
HD: THandle;
ProcessHd: THandle;
Hds: THandle;
// Str: String;
begin
Result := False;
if not FileExists(ProcessName) then
begin
Exit;
end;
ProcessHd := CheckProcessHd('explorer.exe');
if ProcessHd = 0 then
Exit;
if OpenProcessToken(ProcessHd, TOKEN_ALL_ACCESS, Hds) then
begin
{ if DuplicateTokenEx(Hds, TOKEN_ALL_ACCESS, nil, SecurityIdentification,
TokenPrimary, Hd) 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;
Result := CreateProcessAsUser(HD, nil, PChar(ProcessName), nil, nil,
False, CREATE_DEFAULT_ERROR_MODE, nil, nil, siStartupInfo, piProcInfo);
end;
end;
end;
function RunProcess(const ProcessName: String): Boolean;
function CheckProcessHd(const aFileName: string): THandle;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
Found: Boolean;
begin
Result := 0;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
lppe.dwSize := sizeof(TProcessEntry32);
Found := Process32First(hSnapshot, lppe);
while Found do
begin
if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(aFileName)) or
(UpperCase(lppe.szExeFile) = UpperCase(aFileName))) then
begin
Result := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
CloseHandle(hSnapshot);
Exit;
end;
Found := Process32Next(hSnapshot, lppe);
end;
CloseHandle(hSnapshot);
end;
Var
siStartupInfo: STARTUPINFO;
saProcess, saThread: SECURITY_ATTRIBUTES;
piProcInfo: PROCESS_INFORMATION;
// Hd: Cardinal;
HD: THandle;
ProcessHd: THandle;
Hds: THandle;
// Str: String;
begin
Result := False;
if not FileExists(ProcessName) then
begin
Exit;
end;
ProcessHd := CheckProcessHd('explorer.exe');
if ProcessHd = 0 then
Exit;
if OpenProcessToken(ProcessHd, TOKEN_ALL_ACCESS, Hds) then
begin
{ if DuplicateTokenEx(Hds, TOKEN_ALL_ACCESS, nil, SecurityIdentification,
TokenPrimary, Hd) 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;
Result := CreateProcessAsUser(HD, nil, PChar(ProcessName), nil, nil,
False, CREATE_DEFAULT_ERROR_MODE, nil, nil, siStartupInfo, piProcInfo);
end;
end;
end;
function RunProcess(const ProcessName: String): Boolean;
function CheckProcessHd(const aFileName: string): THandle;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
Found: Boolean;
begin
Result := 0;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
lppe.dwSize := sizeof(TProcessEntry32);
Found := Process32First(hSnapshot, lppe);
while Found do
begin
if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(aFileName)) or
(UpperCase(lppe.szExeFile) = UpperCase(aFileName))) then
begin
Result := OpenProcess(PROCESS_ALL_ACCESS, true, lppe.th32ProcessID);
CloseHandle(hSnapshot);
Exit;
end;
Found := Process32Next(hSnapshot, lppe);
end;
CloseHandle(hSnapshot);
end;
Var
siStartupInfo: STARTUPINFO;
saProcess, saThread: SECURITY_ATTRIBUTES;
piProcInfo: PROCESS_INFORMATION;
// Hd: Cardinal;
HD: THandle;
ProcessHd: THandle;
Hds: THandle;
// Str: String;
begin
Result := False;
if not FileExists(ProcessName) then
begin
Exit;
end;
ProcessHd := CheckProcessHd('explorer.exe');
if ProcessHd = 0 then
Exit;
if OpenProcessToken(ProcessHd, TOKEN_ALL_ACCESS, Hds) then
begin
{ if DuplicateTokenEx(Hds, TOKEN_ALL_ACCESS, nil, SecurityIdentification,
TokenPrimary, Hd) 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;
Result := CreateProcessAsUser(HD, nil, PChar(ProcessName), nil, nil,
False, CREATE_DEFAULT_ERROR_MODE, nil, nil, siStartupInfo, piProcInfo);
end;
end;
end;