Forum Discussion

1222tmiller's avatar
1222tmiller
Occasional Contributor
14 years ago

How do I control "Notepad" that my program opens.

If you have a problem connecting to our system, we automatically do an IP Trace and show it in Notepad.  For the test script to complete, I need to close it.  (using Delphi Script).



How do I get a handle to a program that is already running?

How do I do a Wait for it to open (see my example below)?

How do I close the program gracefully?



This is what I do in other areas for a wait



  while (MyApp.FrmErrorDlg.Exists = false)  do

        aqUtils.Delay(1000); // 1 sec delay



hopefully can do something like



  while (Sys.Process("Notepad").Exists = false)  do

        aqUtils.Delay(1000); // 1 sec delay

1 Reply


  • Hello Tom,





    I recommend that you use the Sys.WaitProcess method to wait for a process. The following script waits for the Notepad process and closes it without saving the changes.







    procedure Test1;

      var notepad : OleVariant;

      var wndNotepad : OleVariant;

    begin

      notepad := Sys.WaitProcess('Notepad', 10000);

      if( notepad.Exists) then 

      begin

         wndNotepad := notepad.Window('Notepad');

         wndNotepad.Close();

         if (notepad.WaitWindow('#32770', 'Notepad').Exists) then

           notepad.WaitWindow('#32770', 'Notepad').Keys('n');

      end;

    end;