Login | |
|
 |
Check Registry whether program is installed - 4/24/2008 4:04:53 AM
|
|
 |
|
| |
irispeeters
Posts: 4
Score: 0
Joined: 4/24/2008
Status: offline
|
Hello, As a new visual basic script user I've been struggling with the following issue: I want to check whether a program (Skyline) is installed before a html is opened, because this program is needed to open an ActiveX embedded in the html page. If the program is not installed, I want to create a popup window with the possibility to download the program (run exe with WshShell.Run), otherwise the html may be opened. As I've done this before in vb code in Visual Studio I started in vbs using the same code: Imports Microsoft.Win32 Function TEInstalled() As Boolean Dim regSkyline As RegistryKey Dim keyValue As String keyValue = "Software\\Skyline" regSkyline = Registry.CurrentUser.OpenSubKey(keyValue, False) Dim intVersion As Integer = 0 If regSkyline Is Nothing Then Return False Else Return True regSkyline.Close() End If End Function However, I soon discovered this was impossible because Microsoft.Win32 could not be used in vbs. I then experimented with set shell = CreateObject("WScript.Shell") and set filesys = CreateObject ("Scripting.FileSystemObject") but nothing worked. I searched again and found the following code: Function RegistryKeyExist(RegistryKey) On Error Resume Next Const METHODNAME = "RegistryKeyExist" Const DUMMYKEY = "HKLM\Software\Skyline\" Dim strDescription 'As String Dim WshShell 'As Object RegistryKeyExist = False Set WshShell = CreateObject("WScript.Shell") If Err.Number <> 0 Then Call QuitScript("Error creating shell object!", METHODNAME, Err.Description, Err.number) End If RegistryKey = Trim(RegistryKey) If Right(RegistryKey, 1) = "\" Then Call WshShell.RegRead(DUMMYKEY) strDescription = Replace(Err.Description, DUMMYKEY, "") End If Err.Clear WshShell.RegRead RegistryKey Equals the Diff between the known error for the input key/value. RegistryKeyExist = (strDescription <> Replace(Err.Description, RegistryKey, "")) msgbox Replace(Err.Description, RegistryKey, "") msgbox registrykeyexist Clear the forced error. Err.Clear Destroy object. Set WshShell = Nothing End Function ... but the result was always "true", even if I changed DUMMYKEY into something absurd. When just using RegRead I got the error "Can't open registry key "HKLM\Software\Skyline\" to read this". In the mean time I even tried calling an exe made in Visual Studio, but also here were problems... I don't know how to solve this, I don't know enough (yet?) about vbscript, but I would like to learn more. Every help would be greatly appreciated! Thanks! Greetings, Iris
|
|
| |
|
|
|
 |
RE: Check Registry whether program is installed - 4/24/2008 10:32:19 PM
|
|
 |
|
| |
mbouchard
Posts: 1835
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
|
Are you looking for the regkey or a particular value in the key?
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
| |
|
|
|
 |
RE: Check Registry whether program is installed - 5/4/2008 8:25:49 AM
|
|
 |
|
| |
Fredledingue
Posts: 326
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
Yes, using On Error Resume Next is the only method to know wether a reg key exists or not without crashing the script. Registry work is limited to three commands: .RegRead .RegWrite .RegDelete Don't forget Set WshShell = CreateObject("Wscript.Shell") at beginning of the script!
_____________________________
Fred
|
|
| |
|
|
|
|
|