Link to home
Start Free TrialLog in
Avatar of WMFS_SUPPORT
WMFS_SUPPORT

asked on

Checking registry subkey with vbscript

I am new to vbscripts and I'm trying to write a script that checks if a wildcard registry subkey exists and perform an action it it does.  I'm struggling with the wildcard entry.  I have tried *, but no luck.  Any advise?

Option Explicit

Dim objShell,objFS,MyDocuments,sRegKey

Set objShell = CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")

sRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\*"
MyDocuments = "\\wm-cls-hme-01\Home\" & objShell.ExpandEnvironmentStrings("%USERNAME%")

'Check to see if a sub registry key exists
If RegKeyExists(sRegKey) Then
 End If
Else
' Create OS folder
 objFS.CreateFolder MyDocuments & "\OS"
' Copy Outlook Profile File
objFS.CopyFile "\\wmfs.net\netlogon\outlook.prf", MyDocuments & "\OS\"

' Import Profile into Outlook
objShell.Run "C:\PROGRA~1\MICROS~2\OFFICE10\OUTLOOK.EXE /IMPORTPRF \\wmfs.net\netlogon\OUTLOOK.PRF"
End If

Function RegValueExists(sRegValue)
     ' Returns True or False based of the existence of a registry value.
     Dim oShell, RegReadReturn
     Set oShell = CreateObject("WScript.Shell")
     RegValueExists = True  ' init value
     On Error Resume Next
     RegReadReturn = oShell.RegRead(sRegValue)
     If Err.Number <> 0 Then
       RegValueExists = False
     End if
     On Error Goto 0
End Function

Function RegKeyExists(ByVal sRegKey)
    ' Returns True or False based on the existence of a registry key.

    Dim sDescription, oShell
    Set oShell = CreateObject("WScript.Shell")

    RegKeyExists = True
    sRegKey = Trim (sRegKey)
    If Not Right(sRegKey, 1) = "\" Then
      sRegKey = sRegKey & "\"
    End If

    On Error Resume Next
    oShell.RegRead "HKEYNotAKey\"
    sDescription = Replace(Err.Description, "HKEYNotAKey\", "")

    Err.Clear
    oShell.RegRead sRegKey
    RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, "")
    On Error Goto 0
End Function
Avatar of Jason Watkins
Jason Watkins
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of WMFS_SUPPORT
WMFS_SUPPORT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did the URL help out at all? If not, you should close this question
Avatar of WMFS_SUPPORT
WMFS_SUPPORT

ASKER

URL was a little helpful, but will close question.