Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Check Registry whether program is installed

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59454
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Check Registry whether program is installed
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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
 
 
Post #: 1
 
 RE: Check Registry whether program is installed - 4/24/2008 5:39:58 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
If you search this forum for something like Registry Key Exists you should find plenty of examples.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to irispeeters)
 
 
Post #: 2
 
 RE: Check Registry whether program is installed - 4/24/2008 6:14:10 PM   
  irispeeters

 

Posts: 4
Score: 0
Joined: 4/24/2008
Status: offline
... yes I've found a few examples, but I keep getting the following error: "Can't open registry key "HKLM\Software\Skyline\" to read this".
I don't know what I'm doing wrong...

But I'll keep on looking.

Thanks for the reply.

(in reply to irispeeters)
 
 
Post #: 3
 
 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.

(in reply to irispeeters)
 
 
Post #: 4
 
 RE: Check Registry whether program is installed - 4/24/2008 11:21:54 PM   
  irispeeters

 

Posts: 4
Score: 0
Joined: 4/24/2008
Status: offline
Hi Mike,

I'm looking for the regkey, no particular value. I just want to know if the Skyline key exists or not.

Thanks,
Iris

(in reply to mbouchard)
 
 
Post #: 5
 
 RE: Check Registry whether program is installed - 4/28/2008 12:04:09 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Please post the code that you are running.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to irispeeters)
 
 
Post #: 6
 
 RE: Check Registry whether program is installed - 4/28/2008 8:48:41 PM   
  irispeeters

 

Posts: 4
Score: 0
Joined: 4/24/2008
Status: offline
I got as far as this:





sub TECheck()
dim RegistryItem
RegistryItem = "HKLM\SOFTWARE\Skyline\"

  if RegistryItemExists(RegistryItem) then
   msgbox "yes"
else
   msgbox "no"
end if

end sub

Function RegistryItemExists (RegistryItem)
On Error Resume Next

  If (Right(RegistryItem, 1) = "\") Then
   WshShell.RegRead RegistryItem

    Select Case Err
     Case 0:
       RegistryItemExists = true
     Case &h80070002:
       ErrDescription = Replace(Err.description, RegistryItem, "")

        Err.clear
        WshShell.RegRead "HKEY_ERROR\"
        If (ErrDescription <> Replace(Err.description, "HKEY_ERROR\", "")) Then
         RegistryItemExists = true
       Else
         RegistryItemExists = false
       End If
     Case Else:
       RegistryItemExists = false
   End Select
Else
   WshShell.RegRead RegistryItem

    Select Case Err
     Case 0:
       RegistryItemExists = true
     Case Else
       RegistryItemExists = false
   End Select
End If

  On Error Goto 0
End Function





When running this code I always get a message box "no", while it should be "yes" as Skyline is installed.

When running different but similar codes I often get the error message "Cannot open registry key "HKLM\SOFTWARE\Skyline\" to read it"

Thanks

(in reply to ebgreen)
 
 
Post #: 7
 
 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

(in reply to irispeeters)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Check Registry whether program is installed Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts