Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

VB Script objReg.EnumKey Object not a collection when opening vbs as shortcut

$
0
0
It's really strange the script works fine if I double click on it, but if I call it from say an email shortcut I sent to my colleuges or shell run it from my other program, it throws the error:

Object not a collection

It fails on this line For Each subkey In arrSubKeys after objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

Here is the important part of the code, I removed the other stuff

vb Code:
  1. Set shl = CreateObject("WScript.Shell")
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. Set objShell = CreateObject("Shell.Application")
  4.  
  5. const AppName = "Helpdesk Toolkit"
  6. const HKEY_LOCAL_MACHINE = &H80000002
  7.  
  8. 'Find Uninstall GUID
  9. Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
  10. strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
  11.  
  12. objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
  13.  
  14. For Each subkey In arrSubKeys
  15.     InstalledAppName = ""
  16.     On Error Resume Next
  17.     InstalledAppName = shl.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\InstallProperties\DisplayName")
  18.     If Err.Number <> 0 Then
  19.     End If
  20.     On Error Goto 0
  21.     If InStr(InstalledAppName, AppName) > 0 then
  22.     RawGUID = ""
  23.     GUID = ""
  24.     RawGUID = shl.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\InstallProperties\UninstallString")
  25.         GUID = Mid(RawGUID, instr(RawGUID, "{"), 38)
  26.     If GUID<>"" then
  27.         ' Found matching GUID, removing...
  28.         msgbox(GUID)
  29.         Exit For
  30.     End If
  31.     End If
  32. Next

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>