PDA

View Full Version : Checking If a Particular Program is Running


Desmond
10-03-2003, 02:31 PM
<HTML> <HEAD> <TITLE>AutoPlay Media Studio 5.0 Knowledge Base</TITLE> </HEAD> <BODY> <h3>Checking If a Particular Program is Running</h3> <b>Document ID: IR10087</b> <hr> The information in this article applies to: <ul> <li>AutoPlay Media Studio 5.0 Professional Edition</li> </ul> <hr> <h3>SUMMARY</h3> <p>This article describes how to check if a particular program is running.</p> <h3>DISCUSSION</h3> <p> 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.<br> <br> Insert the following code into the On Show event of your page:<pre><code>instances_of_file = 0;
<br />--have all lowercase
<br />file_to_check_for = "autorun.exe";
<br />processes = Window.EnumerateProcesses();
<br />
<br />for j, file_path in processes do
<br /> file = String.SplitPath(file_path);
<br /> if (String.Lower(file.Filename..file.Extension)) == file_to_check_for then
<br /> instances_of_file = instances_of_file + 1;
<br /> end
<br />end
<br />
<br />if instances_of_file > 1 then
<br /> Window.Hide(Application.GetWndHandle());
<br /> Dialog.Message("Error", "Autorun already running: code: already running");
<br /> Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
<br />else
<br /> Window.Show(Application.GetWndHandle());
<br />end</code></pre> <h3>MORE INFORMATION</h3> <p>For more information please see the following topics in the AutoPlay Media Studio 5.0 help file:</p> <ul> <li><b>Program Reference | Actions | Window | Window.EnumerateProcesses</b></li> <li><b>Program Reference | Actions | Application | Application.GetWndHandle</b></li> </ul> <p>KEYWORDS: AutoPlay Media Studio 5.0, Window, Application, Find, Running </p> <hr> <FONT SIZE=1> Last reviewed: October 3, 2003<br> Copyright © 2003 <A HREF="http://www.indigorose.com" target="blank">Indigo Rose Corporation</a>. All rights reserved.<br> </FONT> </BODY> </HTML>