Blog content

Latest posts

Active categories:

More tags ...

By date:

    (No recent posts)

Blog calendar

November 2017
Mo Tu We Th Fr Sa Su
 << Oct Dec >>
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

Blog features

RSS feed icon RSS feed

RSS comment feed icon RSS comment feed

Quoting strings in INF AddReg sections

posted by Martin Rubli at 07:35

The syntax of the INF files controlling Windows driver installation can be a little tricky at times. In this particular case I was trying to add a registry key whose value contains some quoted paths. It took me several attempts to get it right and the help on INF strings sections was also rather cryptic and not very helpful with its lack of examples.

I wanted to create a key with the following value (of course the actual example was slightly different but this will do to illustrate the problem):

"C:\Program Files\MyTool\Run.exe" -datadir"C:\Program Files\MyTool\data\" -debug -title"MyTool" -verbose

Here's the solution (or should I say: the closest I got):

[MyTool.Addreg]
HKLM,Software\Me\MyTool,Command,0x00000000,"""C:\Program Files\MyTool\Run.exe""" -debug -datadir"""C:\Program Files\MyTool\data\""" -title"""MyTool""" -verbose""

The documentation states:

[...] any string [...] that is itself a quoted string, must be enclosed in a pair of double quotation marks characters [...]
The INF parser not only discards the outermost pair of enclosing double quotation marks for any "quoted string" in this section, but also condenses each subsequent sequential pair of double quotation marks into a single double quotation marks character. That is, """some string""" also becomes "some string" when it has been parsed.

The second paragraph is slightly beyond my understanding, in particular considering some of my intermediary test results that you can find at the bottom.

The first paragraph at least explains the double quotes at the end. Inside the string all quotes also need to be tripled.

The beginning of the remains somewhat of a mystery to me. The triple quote at the beginning of the string is converted into a single quote in the registry.

To make matters worse, Microsoft's own ChkInf, which comes with the DDK, doesn't like any of the working solutions. It doesn't accept any less than four quotes at the end of the string. However, with more than two quotes at the end of the string, the resulting registry ends up containing a trailing quote. Anything with two or fewer (one and zero also work but at least seem syntactically incorrect to me) works fine with regard to the end result.

As I promised, here are some of my intermediary results. The slightly simplified AddReg commands and the corresponding result behind the semicolon:

HKLM,,TestA,0x00000000,"""Some string"""              ; "Some string"
HKLM,,TestB,0x00000000,""Some ""quoted"" string""     ; Some string
HKLM,,TestC,0x00000000,""Some "quoted" string""       ; Some string
HKLM,,TestD,0x00000000,""Some \"quoted\" string""     ; Some \quoted\ string
HKLM,,TestE,0x00000000,""Some """quoted""" string""   ; Some "quoted" string

Is anyone wondering why Microsoft didn't just adopt the syntax of one of the many programming languages out there where similar problems are unheard of? The developers could have just copied the code from MSVC (or any of the other hundreds of MS implementations of the same algorithm) and users wouldn't have to even read the documentation. But heaven forbid a win-win situation!


Leave a comment

Your comment: