PDA

View Full Version : Single Instance



mitjpl
03-29-2007, 08:55 AM
Hi. I've made an AutoPlay CD browser. I notice that if the user clicks on the CD more than once, multiple instances of the CD browser will be launched. Is there a way to limit my AutoPlay executable so only a single instance will run at a time?

Thanks in advance.

--Jim

mwreyf1
03-29-2007, 10:02 PM
Try this:

It's from the AMS Help file.

You will need to modify to fit your needs.

As an example, let us assume that you want to run your program, 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.



instances_of_file = 0;
file_to_check_for = "autorun.exe"; --have all lowercase
processes = Window.EnumerateProcesses();

for j, file_path in processes do
file = String.SplitPath(file_path);
if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then
instances_of_file = instances_of_file + 1;
end
end

if instances_of_file > 1 then
Window.Hide(Application.GetWndHandle());
Dialog.Message("Error", "Autorun already running: code: already running");
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
else
Window.Show(Application.GetWndHandle());
end