Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Binary Registry Settings (VB/VBA)

    So much for MSKB. I'm trying to change a registry setting through VBA by using VBScript. I've been successful using string values, but now I'm having a problem trying to set a binary value. (The value corresponds to a checkbox in Adobe's PDFMaker Conversion Settings.)
    The line of code I'm using to turn the checkbox off is:

    VBSShell.RegWrite "HKCUSoftwareAdobeAcrobatPDFMaker5.0OutputOptionsC reateStructureWD9", 0, "REG_BINARY"

    The problem is that when I run the code, the actual registry entry (shown below) is not what I'm expecting, and it has no effect on the checkbox in question, i.e. the checkbox is still selected. The correct value should just be "00" not "00 00"

    What's up with that?
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Binary Registry Settings (VB/VBA)

    Just a guess here, but maybe 00 00 is unicode for zero (0)? If you use a hex zero (&H00) does it work any better?

  3. #3
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Binary Registry Settings (VB/VBA)

    Unfortunately, it gives me the same result (a value of "00 00").
    I don't know why I expected MSKB to actually help me out, but hope springs eternal.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Binary Registry Settings (VB/VBA)

    Hi,
    I confess I don't know exactly why it does that - I suspect it has something to do with the fact you're using an integer (RegWrite only accepts strings or integers). I would use APIs to get around this - something like:
    <pre>Private Declare Function RegCloseKey Lib "advapi32.dll" _
    (ByVal hKey As Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" _
    Alias "RegOpenKeyA" (ByVal hKey As Long, _
    ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" _
    Alias "RegSetValueExA" (ByVal hKey As Long, _
    ByVal lpValueName As String, ByVal Reserved As Long, _
    ByVal dwType As Long, lpData As Any, _
    ByVal cbData As Long) As Long
    Const REG_BINARY = 3
    Const HKEY_CURRENT_USER = &H80000001
    Sub ChangeBinKey()
    Dim retVal
    RegOpenKey HKEY_CURRENT_USER, _
    "SoftwareAdobeAcrobatPDFMaker5.0OutputOptions" , retVal
    RegSetValueEx retVal, "CreateStructureWD9", 0, REG_BINARY, CByte("0"), 1
    RegCloseKey retVal
    End Sub
    </pre>

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Binary Registry Settings (VB/VBA)

    Well, that certainly did the trick. Thanks.

    I'm stilled bummed and confused that VBScript failed me, and frustrated that the documentation (such as it is) must either be incomplete or wrong. It works just fine with strings, but the integer bit weirds me out.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Binary Registry Settings (VB/VBA)

    95% or more of all users never need to deal with the registry directly.
    95% or more of those who need to use the registry, can do so interactively, in RegEdit.
    95% or more of those who need to program the registry, only need to read and write string and integer values. The RegRead and ReagWrite functions are meant for them - an easy "wrapper" that hides the complexities.
    The very small number of people who need to be able to do everything with the registry, need to use Windows API functions... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  7. #7
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Binary Registry Settings (VB/VBA)

    Woo-hoo! Not that I'm reluctant to use Windows' API, but I found the answer for the VBScript approach. The key (so to speak) is that I need to pass the value using the cByte function, i.e.:

    Sub Test()
    Dim VBSShell As Object
    Set VBSShell = CreateObject("WScript.Shell")
    VBSShell.RegWrite "HKCUSoftwareAdobeAcrobatPDFMaker5.0OutputOptionsC reateStructureWD9", CByte("0"), "REG_BINARY"

    Set VBSShell = Nothing
    End Sub

    Hope this helps anyone else who might be faced with the same issue.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Binary Registry Settings (VB/VBA)

    Hey, great! I'm glad you found it and shared it with us. Thanks.

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Binary Registry Settings (VB/VBA)

    > VBSShell.RegWrite
    Thanks.
    I have extended this (for another project) and can now:<pre>VBSShell.Regdelete "HKCUSoftwareAdobeAcrobatPDFMaker5.0OutputOptionsC reateStructureWD9"</pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •