Checking registry subkey with vbscript

WMFS_SUPPORT
WMFS_SUPPORT used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jason WatkinsIT Project Leader

Commented:
Fixed script.  This is the finished script: -

Option Explicit

Dim objShell,objFS,MyDocuments,sRegKey,sRegValue

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

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

' Check to see if the Outlook DefaultProfile registry key exists
If not (RegKeyExists(sRegKey) And RegValueExists(sRegValue)) Then
      ' Create OS folder if Default Profile is missing
      objFS.CreateFolder MyDocuments & "\OutlookPRF"
      ' Copy Outlook Profile File
      objFS.CopyFile "\\wmfs.net\netlogon\outlook.prf", MyDocuments & "\OutlookPRF\"
      ' Import Profile into Outlook which creates Outlook profile based upon username
      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
Jason WatkinsIT Project Leader

Commented:
Did the URL help out at all? If not, you should close this question

Author

Commented:
URL was a little helpful, but will close question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial