Re: Using vbBinaryCompare

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 02/14/05


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


Relevant Pages

  • Re: Information bar problem
    ... Are u able to execute any script on ur system after registry patch,cos in my ... effect any ActiveX or Scripts on my system. ... removing the Information bar, ... To turn off the Information Bar for file downloads, ...
    (microsoft.public.windowsxp.general)
  • Re: I WANT to see Recent Documents
    ... I am not in a corporate enviornment and have no scripts or anything like that. ... I went to the Registry location and did not see anything that was obvious ... Word MVP web site http://word.mvps.org ...
    (microsoft.public.word.docmanagement)
  • Re: Newbie: where to start?
    ... I'm also after the wsh object model. ... Many scripts are included on the included CD that demonstrate the ... about to change the registry. ... simply restore that backup to undo changes. ...
    (microsoft.public.scripting.vbscript)
  • Re: HTTP 500.100 - Internal Server Error - ASP error
    ... whether the correct components are installed and registered as they should ... verify that your script is coded properly by using these scripts as ... > enabling it to launch permissions on COM+ objects. ... > some have recommended changes to the Registry and to Local Security ...
    (microsoft.public.inetserver.iis)
  • Re: Saving attachments
    ... > I don't recall the message discussing modifying the registry. ... >> Or MVP Kelly Theriots has written scripts. ... >> Kath Adams ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)