garys

Accessing Registry from VBScript

I'm no VB guy but have been trying everything to access the registry from VBScript in a Custom Action.

I want to preserve some files when a user moves up to a new version, so I'm using an Install CA to copy the files to a tmp directory and a Commit CA to copy them back. (If there's a better way, please let me know!)

My VBScript works fine outside the installer but fails in it. Here's the problem code with the JRE key used for testing:

Code: Select all

Dim oShell
On Error Resume Next
Set oShell = WScript.CreateObject("WScript.Shell")
If Err.number <> 0 Then
  MsgBox "Error in shell", 16, "error"
  MsgBox Err.number, 16, "error"
  Err.Clear
End If
Using the MsgBox calls, I've found that the Err.number for the creating the oShell is 500: "Variable is undefined". Does this refer to WScript? I saw Cata's post that "the scripts are not actually hosted inside a wscript session" but he then suggested that "You should CreateObject a wscript object yourself (for example "WScript.Shell")." What am I doing wrong?

FYI, I also tried using CRegistry as per Peter Furnett's post but that didn't work for me even outside the installer (didn't get the value).

Can anyone help me out of VB hell?

Thanks.

gs
garys

Got it

Finally got it to work. Changed

Code: Select all

WScript.CreateObject("WScript.Shell")
to

Code: Select all

CreateObject("WScript.Shell")
and that's working.

gs

Return to “Common Problems”