Post by therealmethuselah on Nov 20, 2005 12:12:50 GMT -5
When you install some software, you can choose where you install it to. I don't know about you, but sometimes I like to change the default value.
So, what if you wanted to know if a user has a program like 7-zip installed, or if he/she's a programmer if they have Notepad++.
You can't just do this:
What if the user did not install Windows to his/her C:\ drive, or what if the user chose to install the program in a different directory?
Well, we're going to check the registry key for the value. We'll call our script. checkForProgram();
As you can see our script has 3 arguments:
- argument0: The key under HKEY_LOCAL_MACHINE\SOFTWARE\ where the software writes it's value
- argument1: The name of the .exe itself
- argument2: The registry key where the Path is stored
So now, if we want to know where the user really installed 7-Zip, we'd use this code:
checkForProgram('7-Zip', '7zFM.exe', 'Path');
And for Notepad++ we'd use:
checkForProgram('Notepad++', 'notepad++.exe', '');
As you can see, the script returns either true or false.
So you could use this code to see if they have the program
Now let's try a hard one, QuickTime
checkForProgram('Apple Computer, Inc.\QuickTime', 'QuickTimePlayer.exe', 'InstallDir');
So, what if you wanted to know if a user has a program like 7-zip installed, or if he/she's a programmer if they have Notepad++.
You can't just do this:
if (file_exists('C:\Program Files\Notepad++\notepad++.exe'))
{
...
}
{
...
}
What if the user did not install Windows to his/her C:\ drive, or what if the user chose to install the program in a different directory?
Well, we're going to check the registry key for the value. We'll call our script. checkForProgram();
{
// Set the registry to HKEY_LOCAL_MACHINE
registry_set_root(1);
// Check if the particular Program entry exists
if (registry_exists_ext('\SOFTWARE\' + argument0, argument2)) {
checkPath = registry_read_string_ext('\SOFTWARE\' + argument0, argument2) + '\' + argument1;
return true
}
else {
checkPath = '';
return false
}
}
// Set the registry to HKEY_LOCAL_MACHINE
registry_set_root(1);
// Check if the particular Program entry exists
if (registry_exists_ext('\SOFTWARE\' + argument0, argument2)) {
checkPath = registry_read_string_ext('\SOFTWARE\' + argument0, argument2) + '\' + argument1;
return true
}
else {
checkPath = '';
return false
}
}
As you can see our script has 3 arguments:
- argument0: The key under HKEY_LOCAL_MACHINE\SOFTWARE\ where the software writes it's value
- argument1: The name of the .exe itself
- argument2: The registry key where the Path is stored
So now, if we want to know where the user really installed 7-Zip, we'd use this code:
checkForProgram('7-Zip', '7zFM.exe', 'Path');
And for Notepad++ we'd use:
checkForProgram('Notepad++', 'notepad++.exe', '');
As you can see, the script returns either true or false.
So you could use this code to see if they have the program
if (checkForProgram('Notepad++', 'notepad++.exe', '') == true) {
...
}
...
}
Now let's try a hard one, QuickTime
checkForProgram('Apple Computer, Inc.\QuickTime', 'QuickTimePlayer.exe', 'InstallDir');