• Binary Registry Settings (VB/VBA)

    Author
    Topic
    #388417

    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.0OutputOptionsCreateStructureWD9”, 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?

    Viewing 1 reply thread
    Author
    Replies
    • #681924

      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?

      • #682139

        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.

    • #682162

      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:

      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
      

      Hope that helps.

      • #682186

        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.

        • #682237

          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… shrug

          • #683071

            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.0OutputOptionsCreateStructureWD9”, CByte(“0”), “REG_BINARY”

            Set VBSShell = Nothing
            End Sub

            Hope this helps anyone else who might be faced with the same issue.

            • #683109

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

            • #932253

              > VBSShell.RegWrite
              Thanks.
              I have extended this (for another project) and can now:

              VBSShell.Regdelete "HKCUSoftwareAdobeAcrobatPDFMaker5.0OutputOptionsCreateStructureWD9"
    Viewing 1 reply thread
    Reply To: Binary Registry Settings (VB/VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: