Desmond
09-26-2003, 09:46 AM
<HTML> <HEAD> <TITLE>Running my Application Only Once</TITLE> </HEAD> <BODY> <h3>Running my Application Only Once</h3> <b>Document ID: IR10013</b> <hr> The information in this article applies to: <ul> <li>AutoPlay Media Studio 5.0 Standard Edition</li> <li>AutoPlay Media Studio 5.0 Professional Edition</li> </ul> <hr> <h3>SUMMARY</h3> <p>This article describes how to prevent your application from running more than once. </p> <h3>DISCUSSION</h3> <p>To run your application only once (i.e. the first time the user inserts your CD-ROM, and no other time), place the following code in the On Startup event of your project:<code><pre>--retrieve value from the registry. If the key does not exist, result = ""
<br />result = Application.LoadValue("Application_Name", "First_Time");
<br />
<br />--if there was no key, the program has never been run
<br />if result == "" then
<br /> --if there is no value set, the string will be empty
<br /> Application.SaveValue("Application_Name", "First_Time", "yes");
<br /> Dialog.Message("title", "this is the first time this program has run");
<br />else
<br /> Application.Exit();
<br />end</pre> </code> <p>As an alternative, Pro Edition users can use Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE) in place of Application.Exit(). This will close the window before the window draws itself (i.e. the user will see nothing). <h3>MORE INFORMATION</h3> <p>For more information please see the following topics in the AutoPlay Media Studio 4.0 help file:</p> <ul> <li><b>Program Reference | Actions | TextFile | TextFile.WriteFromString</b></li> </ul> <p> KEYWORDS: AutoPlay Media Studio 5.0, Actions, Write, Text, File, Overwrite, Append, Disk </p> <hr> <FONT SIZE=1> Last reviewed: September 26, 2003<br> Copyright © 2003 <A HREF="http://www.indigorose.com" target="blank">Indigo Rose Corporation</a>. All rights reserved.<br> </FONT> </BODY> </HTML>
<br />result = Application.LoadValue("Application_Name", "First_Time");
<br />
<br />--if there was no key, the program has never been run
<br />if result == "" then
<br /> --if there is no value set, the string will be empty
<br /> Application.SaveValue("Application_Name", "First_Time", "yes");
<br /> Dialog.Message("title", "this is the first time this program has run");
<br />else
<br /> Application.Exit();
<br />end</pre> </code> <p>As an alternative, Pro Edition users can use Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE) in place of Application.Exit(). This will close the window before the window draws itself (i.e. the user will see nothing). <h3>MORE INFORMATION</h3> <p>For more information please see the following topics in the AutoPlay Media Studio 4.0 help file:</p> <ul> <li><b>Program Reference | Actions | TextFile | TextFile.WriteFromString</b></li> </ul> <p> KEYWORDS: AutoPlay Media Studio 5.0, Actions, Write, Text, File, Overwrite, Append, Disk </p> <hr> <FONT SIZE=1> Last reviewed: September 26, 2003<br> Copyright © 2003 <A HREF="http://www.indigorose.com" target="blank">Indigo Rose Corporation</a>. All rights reserved.<br> </FONT> </BODY> </HTML>