Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Yet another VBScript registry key value question

Status
Not open for further replies.

MidMoRog

IS-IT--Management
Apr 30, 2009
3
US
Hi all. I'm very much a novice Vbscripter, so please be gentle. I have a script that I'm trying to have look for a value in the regitstry. If this value exists, I want it to write that same value to another key.

Here's the code I have so far. I have verified that the keys exist and that the value is correct, but the script keeps telling me that the product is not installed. I'd really appreciate any help. Don't have much hair as it is and I'm pulling that out! THANKS


Set WS = CreateObject("wscript.shell")
Set WshShell = Wscript.CreateObject("Wscript.Shell")

if RegistryValueExists("HKEY_CLASSES_ROOT\Installer\Products\E93843F1628446B41B3B245EEAD8CEA5\ProductName\ArcGIS Desktop 9.2 Concurrent") = false Then
MsgBox "Product Not installed"
Else
WS.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E93843F1628446B41B3B245EEAD8CEA5}\DisplayName","ArcGIS Desktop 9.2 Concurrent"
end If

Function RegistryValueExists(RegistryValue)
'Ensure the last character is NOT a backslash (\) - if it is, we aren't looking for a value
If (Right(RegistryValue, 1) = "\") Then
'It's not a registry value we are looking for
RegistryValueExists = false
Else
'If there isnt the value when we read it, it will return an error, so we need to resume
On Error Resume Next

'Try reading the value
WshShell.RegRead RegistryValue

'Catch the error
Select Case Err
Case 0:
'Error Code 0 = 'success'
RegistryValueExists = True
Case Else
'Any other error code is a failure code
RegistryValueExists = False
End Select

'Turn error reporting back on
On Error Goto 0
End If

End Function
 
I'd use this:
If Not RegistryValueExists("HKEY_CLASSES_ROOT\Installer\Products\[!]{[/!]E93843F1628446B41B3B245EEAD8CEA5[!]}[/!]\ProductName\ArcGIS Desktop 9.2 Concurrent") Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, thanks for the reply but it still does the same thing and tells me that the product is not installed.
 
[0] The mapping hklm and hkcr for the installed software as shown is not generally valid. It can be correct for some, not at all so for others. I take op's word and assume the correspondance is observed.

[1] The logic for regread is to read the valuename for the value, not to read the value itself as argument.
>if RegistryValueExists("HKEY_CLASSES_ROOT\Installer\Products\E93843F1628446B41B3B245EEAD8CEA5\ProductName\ArcGIS Desktop 9.2 Concurrent") = false Then
should be read:
[tt]if RegistryValueExists("HKEY_CLASSES_ROOT\Installer\Products\E93843F1628446B41B3B245EEAD8CEA5\ProductName") = false Then[/tt]

[1.1] But if the existence of the ProductName entry is not good enough and you want to test if it is exactly written "ArcGIS Desktop 9.2 Concurrent", you can expand the function ResgistryValueExists to take in two argument: one for the path to the valuename and one for the value itself. (But since the guid is not a wild guess, hence, if the scripter has already acquired that info, a verification of the value itself may not be 100% required.)

[2] others
[2.1] The regwrite looks fine except it is better to append the value type "REG_SZ". But that is strictly optional for REG_SZ.
[2.2] WS and WshShell are in practically all aspects the same. Take out one and use consistently the other.
[2.3] For clarity purpose:
>Select Case Err
[tt]Select Case Err[blue].number[/blue][/tt]
[2.4] The logic flow of the script is very case dependent, it should not be taken as a guideline of any generality.
 
RESOLVED!
Thanks to all who responded. While explaining the problem to a coworker I had a revelation. The product code for this version is unique, so all I had to do was make the script look for the product ID key which I was able to do pretty easily. I have distributed the script via sccm and it is working perfectly. I will, however, as time permits look into the solutions sent in by this group. Thanks again and I'm sure I'll post again. Just in case anyone else needs it, here's the code:

on error resume next
Set WshShell = CreateObject("WScript.Shell")
If RegKeyExists("HKEY_CLASSES_ROOT\Installer\Products\E93843F1628446B41B3B245EEAD8CEA5\") Then
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E93843F1628446B41B3B245EEAD8CEA5}\DisplayName","ArcGIS Desktop 9.2 Concurrent DHSS"
End If

Function RegKeyExists(sRegKey)
Dim RegReadReturn
RegKeyExists = True
sRegKey = Trim (sRegKey)
If Not Right(sRegKey, 1) = "\" Then
sRegKey = sRegKey & "\"
End if
On Error Resume Next
RegReadReturn = WshShell.RegRead(sRegKey)
If Err Then
If LCase(Left(err.description,7)) = "invalid" Then
'key not found...
RegKeyExists = False
End if
Err.clear
End if
On Error Goto 0
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top