REG_BINARY data in the registry 
Author Message
 REG_BINARY data in the registry

I had posted a similar response and Ian still has it in newsletter #3 on his
site ( http://www.*-*-*.com/ )

Here is what it was:

If you really must, a cludgy way would be to create an inf file and add the
key with 'rundll32 setupapi'. Here is a sample that I was working on before
I discovered that there is an INF (FLG_ADDREG_APPEND ) flag for appending to
a REG_MULTI_SZ:

~~~~~~~~~~~~~~~~~~~~~~~~~~~
wfilename = WshShell.ExpandEnvironmentStrings("%SystemDrive%") &
"\temp\regtmp.inf"
signat = "Signature = " & Chr(34) & "$Windows NT$" & Chr(34)

'These keys are a REG_MULTI_SZ.  This datatype reads as an array.

'line split to fit page!
ServiceSources =
WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\EventLog\System\Sou
rces")

Set fso = CreateObject("Scripting.FileSystemObject")
Set t = fso.CreateTextFile(wfilename, True)

t.WriteLine("; Temp file to create dynamic REG_MULTI_SZ entries")
t.WriteLine(" ")
t.WriteLine("[Version]")
t.WriteLine(signat)
t.WriteLine(" ")
t.WriteLine("[DefaultInstall]")
t.WriteLine("AddReg = AddReg")
t.WriteLine(" ")
t.WriteLine("[AddReg]")

'line split to fit page
templine = "HKLM," & Chr(34) &
"SYSTEM\CurrentControlSet\Services\EventLog\System" & Chr(34) & "," &
Chr(34) & "Sources" & Chr(34) & ",65536,\"

t.WriteLine(templine)

j = Lbound(ServiceSources)
k = Ubound(ServiceSources)

For i=j to k
    templine = Chr(34) & ServiceSources(i) & Chr(34) & ", \"
    t.WriteLine(templine)
Next
templine = Chr(34) & wSS & Chr(34)
t.WriteLine(templine)

t.Close

The flag will need to be changed to 1 from 65536 (0x10000) in my example
about (along with the rest of what you need) for a Binary value.

Some INF flag values - The flags are defined as follows:
FLG_ADDREG_BINVALUETYPE (0x00000001) The value is "raw" data.
FLG_ADDREG_APPEND (0x00000008) Append a value to an existing value. This
flag is currently supported only for REG_MULTI_SZ values.
FLG_ADDREG_TYPE_MULTI_SZ (0x00010000) Registry data type REG_MULTI_SZ.
FLG_ADDREG_TYPE_BINARY (0x00000000 | FLG_ADDREG_BINVALUETYPE) Registry data
type REG_BINARY.

The command to install the INF would then be:

rundll32 setupapi,InstallHinfSection DefaultInstall 128 c:\temp\regtmp.inf

Since REGEDIT seems to have issues with Binary and other numeric Reg Types
from time to time, the INF format may be a little safer.

The code I had written became obsolete when I found the key
FLG_ADDREG_APPEND:

[AddReg]
HKLM,"SOFTWARE\MYAPP\Stuff","Mysetting",FLG_ADDREG_APPEND,"SillyStuff"

This fixed the need to read and then reapply the MULTI_SZ data.  The example
still should work for binary data after some modification.



    Here's only workaround I've seen, written and posted by David
Stockbridge a few months ago...

    -- Michael Harris



    I am not a programer, but I am working with WSH and REG_BINARY value in
registry. I am not able to query a value like that at all. I am writting
login script that will detect wether a user is connecter remotely by
checking a dynamic value in registry

    HKLM\System\CurrentControlSet\Services\RemoteAccess\Remote Connection.

    How can query the value, the following doesn't work
    Remote =
WshShell.RegRead("HKLM\System\CurrentControlSet\Services\RemoteAccess\Remote
Connection\")

    IF Remote = 1 then
            WshShell.Popup "Remote is ON"
    Else
            WshShell.Popup "Remote is OFF"
    END IF

Quote:
    -----Original Message-----
    From: Udo Frormann

    Posted At: 23/06/99 10:16
    Conversation: Accessing REG_BINARY data in the registry
    Subject:Accessing REG_BINARY data in the registry

    I have a problem accessing data in the registry with type "REG_BINARY".

    If there is only one byte in the data I can read and write this data to
    and
    from the registry. To have access to more than one byte after RegRead, I
    found a
    solution in an other thread.
    The following code fragment works for reading and checking the data :

    val = WSHShell.RegRead( .. key with REG_BINARY data ...)
    for each v in val
      msgbox "Contens of v : " + CStr(v)
    next

    But write to the registry fails every time with "type mismatch" code
    800A000D. The
    contens of variable "val" is the data read in the above RegRead request.
    The data is
    completly read which can be verified with the msgbox in the "for each"
    loop.

    WSHShell.RegWrite ".. key with REG_BINARY data ", val, "REG_BINARY"

    If I put the data directly in the code the write works, but only for
    some few values. If
    the entered value is to long or to big ? (for example &H1234567890)
    results in an VB
    Syntax error.

    WSHShell.RegWrite ".. key with REG_BINARY data ", &H01, "REG_BINARY"

    Any idea to solve this and to write REG_BINARY data directly from an VB
    variable to the
    registry ?

    --

    Best regards
    Udo Frormann



Sun, 09 Dec 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Accessing REG_BINARY data in the registry

2. Writing REG_BINARY values to the Registry

3. Can't update the registry with REG_BINARY value

4. RegWrite & REG_BINARY data

5. Registry data in Outlook agent

6. Detect registry data's repertory

7. Reading perf data from registry help

8. Read data from DB, write to registry via VBscript

9. Reading Binary data from the registry

10. Binary registry data to Jscript Array?

11. Registry Data in Outlook agent

12. Reading REG_BINARY Keys with RegObj.dll

 

 
Powered by phpBB® Forum Software