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.Shel l")
Set objFS = CreateObject("Scripting.Fi leSystemOb ject")
sRegKey = "HKEY_CURRENT_USER\Softwar e\Microsof t\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\*"
MyDocuments = "\\wm-cls-hme-01\Home\" & objShell.ExpandEnvironment Strings("% 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\outlo ok.prf", MyDocuments & "\OS\"
' Import Profile into Outlook
objShell.Run "C:\PROGRA~1\MICROS~2\OFFI CE10\OUTLO OK.EXE /IMPORTPRF \\wmfs.net\netlogon\OUTLOO K.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.Shel l")
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.Shel l")
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
Option Explicit
Dim objShell,objFS,MyDocuments
Set objShell = CreateObject("WScript.Shel
Set objFS = CreateObject("Scripting.Fi
sRegKey = "HKEY_CURRENT_USER\Softwar
MyDocuments = "\\wm-cls-hme-01\Home\" & objShell.ExpandEnvironment
'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\outlo
' Import Profile into Outlook
objShell.Run "C:\PROGRA~1\MICROS~2\OFFI
End If
Function RegValueExists(sRegValue)
' Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject("WScript.Shel
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.Shel
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
Good start, here; http://www.tek-tips.com/faqs.cfm?fid=5864
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did the URL help out at all? If not, you should close this question
ASKER
URL was a little helpful, but will close question.