AutoPlay Media Studio 9

How do I...?

How do I...?

Previous topic Next topic  

How do I...?

Previous topic Next topic  

AnswerList of Questions

Check if a Particular Program is Running

As an example, let us assume that you want to run your program (autorun.exe) only if there is not another autorun.exe running on the system. To accomplish this, use the Window.EnumerateProcesses action and check every process against the filename autorun.exe.

1.Insert the following code into the On Show event of your page:

-- Initialize variables

instances_of_file = 0;

file_to_check_for = "autorun.exe"; --have all lowercase

processes = Window.EnumerateProcesses();

 

-- Step through process table

for j, file_path in pairs(processes) do

 -- Split path to get filename

   file = String.SplitPath(file_path);

 -- compare filename to the file specified in variable initialization

   if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then

     -- The process matches, increment count by 1.

       instances_of_file = instances_of_file + 1;

   end

end

 

-- Check if at least one file matched

if instances_of_file > 0 then

 -- There was at least one match, hide this application window, display error, and close.

   Window.Hide(Application.GetWndHandle());

   Dialog.Message("Error", "Another instance of Autorun.exe is already open.");

   Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);

end


Learn More: Indigo Rose Software - AutoPlay Media Studio - Buy Now - Contact Us