Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


LaunchCommandAndWait

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25253
Location: The netherlands

PostPosted: Fri Apr 29, 2022 9:04 am    Post subject: LaunchCommandAndWait Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 30

Joined: 16 Feb 2017
Posts: 1227

PostPosted: Fri May 06, 2022 2:27 pm    Post subject: Reply with quote

Just a fallback;

The code opens the file at the given path.
But when the file is opened, CE becomes intuitive and out of use, has difficulty working.
CE returns to normal when I close the file.
For CE 7.4 and Windows 10 it responded differently in my case.

Is it normal for the code to disable the CE until the file is closed?

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25253
Location: The netherlands

PostPosted: Fri May 06, 2022 3:15 pm    Post subject: Reply with quote

it's recommended to run it from a thread
_________________
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
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites