How do I... ?
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
How do I... ?
AnswerList of Questions
Close My Application Immediately
Normally to close your application, you should use the Application.Exit() action. However, if you require your application to terminate immediately, instead of using Application.Exit(), use the following code:
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
How do I... ?
AnswerList of Questions
Compare Two Strings
String comparisons are performed in the same manor as number comparisons. As an example, we will create two strings, and perform an action based on their contents:
1. Create two variables containing strings:
String1 = "I am String1"; String2 = "I am String2";
2. Compare the two strings:
if String1 == String2 then
--the two strings are equal else
--the two strings are not equal if String1 > String2 then
--String1 is alphabetically larger than String2 elseif String1 < String2 then
--String1 is alphabetically smaller than String2
end
end
Note: if you want to compare the lengths of two strings, you must use the String.Length action:
if String.Length(String1) == String.Length(String2) then
--the two strings are the same length!!
end
Tip: To perform a non-case-sensitive comparison on two strings, use a String.CompareNoCase action.