PDA

View Full Version : Disable Autorun if Registry Key Exists.


Sean Hook
06-08-2004, 02:18 PM
I am trying to get Autoplay Media studio to NOT run if it detects a given registery key and value.

so basically i want to check to see if the registry value exists, determine what the value is, and if it is less than the version on the CD, the software will run. If it is equal to or greater, the autorun will not be displayed and/or and message will be displayed stating that they already have this software.

I have played with a few different examples i have found, and am starting to get frustrated.

Also, od i want to put this script in the preload area of my first page, or on the onstartup area of the project?

I do not want to use the run once feature, in case the user inserts the disc and has problems/questions and does not proceed.

eric_darling
06-08-2004, 02:47 PM
Why not build a tiny second program using AMS, and make that the autostarting EXE? That way, it will surely autorun every time, but you can have IT check for the registry key - if it doesn't exist, launch the main program EXE and quit. If it does exist, just quit!

Sean Hook
06-09-2004, 10:06 AM
How would i go about specifiying it as greater than or equal to? is that possible in that syntax?

thanks for the help so far.

Bruce
06-09-2004, 10:51 AM
Try this:


--place a text file in your docs folder with your verson #
--When the CD 1st starts place your verson # in the reg.
cd_ver = TextFile.ReadToString("AutoPlay\\Docs\\ver.txt");

Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\whatever\\whatever", "ver", cd_ver, REG_SZ);

cd_ver = TextFile.ReadToString("AutoPlay\\Docs\\ver.txt");

------------------------------Another Page-------------------------
--check for the key
reg_ver = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\whatever\\whatever", "ver", true);
if reg_ver == "" then --the key was empty or does not exist
--Do somthing here
else
ver_compare = String.CompareFileVersions(cd_ver, reg_ver);
if ver_compare == 0 then -- same version
end
elseif ver_compare == 1 then -- cd_ver is greater than the last used version

--do somthing here, I killed the reg. to then write a new one then jumped to page 2
Registry.DeleteKey(HKEY_LOCAL_MACHINE, "Software\\whatever");
Page.Jump("Page2");
end
end


I took this out of another project I was working on with TJ Tigger :yes . I haven't tested it, but it will give you an idea of where we went with it.