Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Checking registry subkey with vbscript

Avatar of WMFS_SUPPORT
WMFS_SUPPORT asked on
Windows XPVB Script
4 Comments1 Solution2418 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Avatar of WMFS_SUPPORT
WMFS_SUPPORT

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers