none
How does one encode double quotes in a Device Update Agent script? RRS feed

  • Question

  • We have a .dus script generator that creates Device Update Agent scripts from difference information.  Recently it generated  a .dus script that contains the commands similar to the following examples:

    11,32768,2147483648,0,Connection Manager Profile\shell\open\command,0,,1,C:\Windows\system32\CMMGR32.EXE "%1"
    11,32768,2147483648,0,Connection Manager Profile\shell\Settings...\command,0,,1,C:\Windows\system32\CMMGR32.EXE /settings "%1"

    Note the quotation marks (") embedded in the REG_SZ values. The problem is that after Device Update Agent executes the commands on the target, the registry does not contain the desired REG_SZ values; the values in the registry are stripped of the quotation marks.

    HKEY_CLASSES_ROOT\Connection Manager Profile\shell\open\command
      C:\Windows\system32\CMMGR32.EXE %1
    HKEY_CLASSES_ROOT\Connection Manager Profile\shell\Settings...\command
      C:\Windows\system32\CMMGR32.EXE /settings %1

    In other scenarios where Device Update Agent botches the assigned value due to the presence of lexical delimiters (i.e. leading or trailing spaces), documentation states that the value may be quoted.  The documentation is not so clear what to do when the lexical construct is itself a quotation mark.

    I intend to try simplistic addition of enclosing quotation marks, and VBscript style embedded quotation marks, but please feel free to respond with any specific knowledge regarding what markup to use that works.  I'll respond to my own question as test results come in so this question can document findings for any other curious soul who may happen to be concerned with such things in the future (however dubious that might be when one considers the age of the tool chain).

    • Edited by Kevin Bulgrien Friday, June 23, 2017 4:39 PM Why isn't this showing up in the forum?
    Friday, June 23, 2017 3:08 PM

Answers

  • The answer is to double-quote (") the whole value and use two consecutive double-quotes ("") each time a double-quote appears inside the value.

    11,32768,2147483648,0,Connection Manager Profile\shell\open\command,0,,1,"C:\Windows\system32\CMMGR32.EXE ""%1"""
    11,32768,2147483648,0,Connection Manager Profile\shell\Settings...\command,0,,1,"C:\Windows\system32\CMMGR32.EXE /settings ""%1""

    This is the "VBscript" style referred to in the original question.

    Friday, June 23, 2017 6:30 PM

All replies

  • The answer is to double-quote (") the whole value and use two consecutive double-quotes ("") each time a double-quote appears inside the value.

    11,32768,2147483648,0,Connection Manager Profile\shell\open\command,0,,1,"C:\Windows\system32\CMMGR32.EXE ""%1"""
    11,32768,2147483648,0,Connection Manager Profile\shell\Settings...\command,0,,1,"C:\Windows\system32\CMMGR32.EXE /settings ""%1""

    This is the "VBscript" style referred to in the original question.

    Friday, June 23, 2017 6:30 PM
  • It may be helpful to add that double-quoting strings is key to preventing other value assignments from breaking on the target:

    1) Strings that contain leading or trailing whitespace.  Without quoting, leading whitespace can be lost.

    2) Strings that contain embedded comma characters.  Without quoting, only the part of the value prior to the first comma is retained.  For a significant number of registry items, this means the assigned value is null since the first character is a literal comma character.

    Friday, June 23, 2017 6:38 PM
  • Sadly, regarding 1 above, DUA deletion of leading and trailing spaces in REG_SZ or REG_EXPAND_SZ values when a script runs on the target,  is not cured by quoting after all.  Device Update Agent apparently treats cuddled commas, quotes, and spaces as parts of a script field delimiter and mercilessly expunges them even when the leading or trailing space characters are INSIDE the quoted string.


    • Edited by Kevin Bulgrien Friday, June 23, 2017 10:09 PM regarding vs. per
    Friday, June 23, 2017 10:07 PM