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 


[Help] Call Exe from delphi

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
mereketehe
How do I cheat?
Reputation: 0

Joined: 30 Jun 2012
Posts: 9

PostPosted: Sat Apr 11, 2015 7:52 am    Post subject: [Help] Call Exe from delphi Reply with quote

Hi guys. I have a problem. How to call exe and open it automatically from button from delphi ?

Example, I already make a form in delphi, and I put the one button there. So, when I click the button, the exe will automatically open.

How to do that? Anyone have the code for me? Smile
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Sat Apr 11, 2015 7:58 am    Post subject: Reply with quote

add "windows" to the uses and call
Code:

ShellExecute(0, PChar('open'), PChar('c:\bla.exe'), nil, nil, 0);   
\
(assuming c:\bla.exe is the exe you wish to call)

_________________
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
mereketehe
How do I cheat?
Reputation: 0

Joined: 30 Jun 2012
Posts: 9

PostPosted: Sat Apr 11, 2015 8:01 am    Post subject: Reply with quote

Dark Byte wrote:
add "windows" to the uses and call
Code:

ShellExecute(0, PChar('open'), PChar('c:\bla.exe'), nil, nil, 0);   
\
(assuming c:\bla.exe is the exe you wish to call)


Thanks darkbyte.

Then, Is it possible that input the EXE to the delphi project. So I call the EXE from the project. Like VB.Net call the exe from the resources.
Back to top
View user's profile Send private message Yahoo Messenger
hhhuut
Grandmaster Cheater
Reputation: 6

Joined: 08 Feb 2015
Posts: 607

PostPosted: Sat Apr 11, 2015 8:59 am    Post subject: Reply with quote

You can also use the CreateProcess API. Since it has very many parameters use the below function instead ...

Code:

type
  TExecuteWaitEvent = procedure(const ProcessInfo: TProcessInformation; var ATerminate: Boolean) of object;

...

procedure ExecuteFile(const AFilename: String;
                 AParameter, ACurrentDir: String; AWait: Boolean;
                 AOnWaitProc: TExecuteWaitEvent=nil);
var
  si: TStartupInfo;
  pi: TProcessInformation;
  bTerminate: Boolean;
begin
  bTerminate := False;
  if Length(ACurrentDir) = 0 then
    ACurrentDir := ExtractFilePath(AFilename);

  if AnsiLastChar(ACurrentDir) = '\' then
    Delete(ACurrentDir, Length(ACurrentDir), 1);

  FillChar(si, SizeOf(si), 0);
  with si do begin
    cb := SizeOf(si);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := SW_NORMAL;
  end;

  FillChar(pi, SizeOf(pi), 0);
  AParameter := Format('"%s" %s', [AFilename, TrimRight(AParameter)]);

  if CreateProcess(Nil, PChar(AParameter), Nil, Nil, False,
                   CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or
                   NORMAL_PRIORITY_CLASS, Nil, PChar(ACurrentDir), si, pi) then
  try
    if AWait then
      while WaitForSingleObject(pi.hProcess, 50) <> Wait_Object_0 do
      begin
        if Assigned(AOnWaitProc) then
        begin
          AOnWaitProc(pi, bTerminate);
          if bTerminate then
            TerminateProcess(pi.hProcess, Cardinal(-1));
        end;

        Application.ProcessMessages;
      end;
  finally
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
  end;
end;


AFileName = Path to your EXE-File (can also be a relative path)
AParamter = The parameter(s) you want to give the program
ACurrentDir = An alternate start directory. Leave empty if you want to use the actual exe directory
AWait = The calling program waits, until the exe file is closed before executing the next instruction

You can call it like this:

Code:
ExecuteFile('C:\bla.exe', '', '', False);
Back to top
View user's profile Send private message
mereketehe
How do I cheat?
Reputation: 0

Joined: 30 Jun 2012
Posts: 9

PostPosted: Sat Apr 11, 2015 9:24 am    Post subject: Reply with quote

hhhuut wrote:
You can also use the CreateProcess API. Since it has very many parameters use the below function instead ...

Code:

type
  TExecuteWaitEvent = procedure(const ProcessInfo: TProcessInformation; var ATerminate: Boolean) of object;

...

procedure ExecuteFile(const AFilename: String;
                 AParameter, ACurrentDir: String; AWait: Boolean;
                 AOnWaitProc: TExecuteWaitEvent=nil);
var
  si: TStartupInfo;
  pi: TProcessInformation;
  bTerminate: Boolean;
begin
  bTerminate := False;
  if Length(ACurrentDir) = 0 then
    ACurrentDir := ExtractFilePath(AFilename);

  if AnsiLastChar(ACurrentDir) = '\' then
    Delete(ACurrentDir, Length(ACurrentDir), 1);

  FillChar(si, SizeOf(si), 0);
  with si do begin
    cb := SizeOf(si);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := SW_NORMAL;
  end;

  FillChar(pi, SizeOf(pi), 0);
  AParameter := Format('"%s" %s', [AFilename, TrimRight(AParameter)]);

  if CreateProcess(Nil, PChar(AParameter), Nil, Nil, False,
                   CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or
                   NORMAL_PRIORITY_CLASS, Nil, PChar(ACurrentDir), si, pi) then
  try
    if AWait then
      while WaitForSingleObject(pi.hProcess, 50) <> Wait_Object_0 do
      begin
        if Assigned(AOnWaitProc) then
        begin
          AOnWaitProc(pi, bTerminate);
          if bTerminate then
            TerminateProcess(pi.hProcess, Cardinal(-1));
        end;

        Application.ProcessMessages;
      end;
  finally
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
  end;
end;


AFileName = Path to your EXE-File (can also be a relative path)
AParamter = The parameter(s) you want to give the program
ACurrentDir = An alternate start directory. Leave empty if you want to use the actual exe directory
AWait = The calling program waits, until the exe file is closed before executing the next instruction

You can call it like this:

Code:
ExecuteFile('C:\bla.exe', '', '', False);


can you give me an example ?
Back to top
View user's profile Send private message Yahoo Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Apr 11, 2015 2:44 pm    Post subject: Reply with quote

mereketehe wrote:
can you give me an example ?


Are you serious..? You just quoted his entire post that is an example....

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming 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