Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've run into a problem in which my experience (and Google-fu) have let me down.

Basically, I need to push out KB968730 to a couple hundred clients or so. Naturally, would like to check for the installation of the hotfix before kicking off the install. Sadly, I need to do this with a script and a GPO, rather than a proper system like SCCM. Not normally something that would give me any issues, but, there seems to be a catch.

The catch is that the path to the registry key this hotfix installs has a bloody space in it. Specifically, it installs to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix\KB968730.

No surprise then, that the standard batch file/CMD command reg.exe query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix\KB968730 throws a syntax error and messes up the installation check part of my batch file - it's seeing the second part of the path as a second argument. So, of course, I tried encapsulating the path in double quotes, no joy. Single quotes, no joy. Threatening my operating system and/or Microsoft also did not produce results.

After some Googling and expletives, I found what seems to be a solution to this, but can't quite get it working, for some reason I can't figure out. (Undoubtedly because my coding skills are weak these days and string tokenization threw me for a loop at the best of times.)

Seems like what I want to use is something like:

for /f "Tokens=2,*" %%a in (‘reg.exe "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix\KB968730" /v Path’) do (set xpath=%%a) and then work with %xpath%, but that's not working. Having tokens set to 1 gives me path before the space, set to 2 gives me the path after the space, and I can't figure out how to append the one value to the other. Particularly frustrating since all the answers I've seen said "thanks, it worked!!!" or similar. *(With the caveat that you remove one % when executing directly on the command line.)

Anyone know what I'm messing up here?

Alternately, if anyone still uses VBS and knows how to do it with that, I'd happily jump at that option. (No PowerShell, though, on account of our XP client not having it installed.)

P.S., if this is better suited for StackOverflow, I've no issues with it being migrated, but my initial thought was that "we" don't appreciate developers coming in here and asking [to us] trivial questions about setting up their dev machines, so I thought they'd probably feel the same way about my question.

share|improve this question
1  
Did you try SET XPATH=%%A%%B%%C? –  jscott Jul 19 '12 at 22:00
    
Um, amazingly, I did not. I'll fire up an XP VM and check now, though. –  HopelessN00b Jul 19 '12 at 22:04
1  
Also of note, double quotes seem to work fine for registry paths containing spaces. Just tested on XPSP3 here: reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" returns the expected keys/values. –  jscott Jul 19 '12 at 23:40
    
Yeah, thank you for that... just noticed that on my home XP VM. Which means there is something deeply fscked up about the XP images at my shop. sigh Might need to retitle this question. "I made a rookie scripting mistake and the last admin was a moron. How do I kill him or regain my dignity?" –  HopelessN00b Jul 19 '12 at 23:47
    
@jscott If you'd be so kind as to put that double quotes comment in an answer, I think that ought to be the accepted answer here. No need to risk leading some other admin down the dark path of string tokenization because there's something horribly amiss about my environment (or test laptops, at least). –  HopelessN00b Jul 20 '12 at 12:33
add comment

1 Answer

up vote 3 down vote accepted

Double quotes seem to work fine for registry paths containing spaces. I've just tested on Windows XP SP3 here. The following returns the expected keys/values:

REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"

Should you want to use tokens, you'll need to use the delims option to specify not to use space/tab as a delimiter. From FOR /?:

   delims=xxx      - specifies a delimiter set.  This replaces the
                     default delimiter set of space and tab.

Simple batch example using ; as a delimiter.

FOR /F "usebackq delims=;" %%A IN (`REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix\KB968730" /v Path`) DO (
    SET XPATH=%%A
)

In addition, you may find the wmic utility helpful. It comes with XP and uses WMI to do it's thing. You can do a quick check for your KB with something like:

wmic qfe list brief | FIND /I "KB968730"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.