Re: Using vbBinaryCompare
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 02/14/05
- Next message: SO: "Change local Administrator account name?"
- Previous message: Torgeir Bakken \(MVP\): "Re: Scipt to update XP"
- In reply to: jp: "Re: Using vbBinaryCompare"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 10:46:10 +0100
jp wrote:
> My explanation or question may not have been very clear here.
>
> What i was meaning about in the registry was its use to validate
> binary values in the registry.
>
> In my vbs scripts i look in the registry for a value being equal or
> false (DWORD, SZ) however when it comes to BINARY I have had to forego
> this validation process because my scripts always crashes.
>
> My validation code is something i found here and works a treat except
> for binary fields.
>
> sRegValue is just that -
> "HKCU\Software\Microsoft\MediaPlayer\Preferences\SendUserGUID"
>
> sDataValue is 0
>
> Key is REG_BINARY
>
> --------- sample
>
> '----------------------------------------------------------+----------------------------------------------------------
> ' Helper function tests whether the registry key exists:
> '----------------------------------------------------------+----------------------------------------------------------
> Function KeyExists(sRegValue)
> Dim key2
> On Error Resume Next
> key2 = WshShell.RegRead(sRegValue)
> sRegLive = key2
> If key2 = sDataValue Then
> KeyExists = True
> Set key2 = Nothing
> Else
> KeyExists = False
> Set key2 = Nothing
> End If
> On Error GoTo 0
> End Function
>
> ----------sample end
>
>
> Becasue Key maybe 00 or 00,00,00,00 I can not validate it properly
> with above code.
>
> Also the above fails when the registry value does not exist at all so
> I am working on that as well.
Hi
To check if a registry key or value exists, you can use the
RegKeyExists and RegValueExists functions in the scripts in
the links below.
With the WshShell's RegRead method ("pure" WSH code):
http://groups.google.co.uk/groups?selm=%23t94ENtLEHA.2532%40TK2MSFTNGP10.phx.gbl
With WMI:
http://groups.google.co.uk/groups?selm=4027FB99.5DFF5864%40hydro.com
Binary values is returned as a VBArray of integers by WSH's RegRead.
Here is an example on how you can handle the SendUserGUID value:
'--------------------8<----------------------
sRegValue = "HKCU\Software\Microsoft\MediaPlayer\Preferences\SendUserGUID"
arrSendUserGUID = RegRead(sRegValue)
' binary values are returned as an array of integers
If IsArray(arrSendUserGUID) Then
If arrSendUserGUID(0) = 1 Then
WScript.Echo "'Send unique Player ID to content providers' is enabled"
Else
WScript.Echo "'Send unique Player ID to content providers' is not enabled"
End If
Else
WScript.Echo "SendUserGUID value does not exist or is not in binary format"
End If
Function RegRead(ByVal sRegValue)
Set oShell = CreateObject("WScript.Shell")
On Error Resume Next
RegRead = oShell.RegRead(sRegValue)
' If the value does not exist, error is raised
If Err Then
RegRead = ""
Err.clear
End If
' If a value is present but uninitialized the RegRead method
' returns the input value in Win2k.
If VarType(RegRead) < vbArray Then
If RegRead = sRegValue Then
RegRead = ""
End If
End If
On Error Goto 0
End Function
'--------------------8<----------------------
-- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx
- Next message: SO: "Change local Administrator account name?"
- Previous message: Torgeir Bakken \(MVP\): "Re: Scipt to update XP"
- In reply to: jp: "Re: Using vbBinaryCompare"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|