Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Fri Apr 29, 2022 9:04 am Post subject: LaunchCommandAndWait |
|
|
Sometimes you wish you could just execute a program in the searchpath and wait for it to finish. This function will do that
Code: |
function LaunchCommandAndWait(command)
local lpStartupInfo=createMemoryStream()
local lpProcessInfo=createMemoryStream()
local sisize
local pisize
local r
local result
if cheatEngineIs64Bit() then
sisize=104
pisize=24
else
sisize=68
pisize=16
end
lpStartupInfo.writeDword(sisize)
lpStartupInfo.Size=sisize
lpProcessInfo.Size=pisize
r=executeCodeLocalEx('CreateProcessA',0,command,0,0,0,0,0,0,lpStartupInfo.Memory,lpProcessInfo.Memory);
if r~=0 then
lpProcessInfo.Position=0
local hProcess
local hThread
if cheatEngineIs64Bit() then
hProcess=lpProcessInfo.readQword()
hThread=lpProcessInfo.readQword()
else
hProcess=lpProcessInfo.readDword()
hThread=lpProcessInfo.readDword()
end
r=executeCodeLocalEx('WaitForSingleObject', hProcess, 0xffffffff)
local ExitCode=createMemoryStream()
ExitCode.Size=4
if executeCodeLocalEx('GetExitCodeProcess', hProcess, ExitCode.Memory)~=0 then
result=ExitCode.readDword()
end
ExitCode.destroy()
--cleanup handles
executeCodeLocalEx('CloseHandle', hProcess)
executeCodeLocalEx('CloseHandle', hThread)
end
lpProcessInfo.destroy()
lpStartupInfo.destroy()
return result
end
|
e.g:
LaunchCommandAndWait('notepad.exe d:\\bla.txt')
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|