0x0 was unexpected at this time

Microsoft Windows vista ultimate w/ sp1...
September 10, 2009 at 14:58:32
Specs: Windows Vista
I'm attempting to use a registry query call that works fine in XP but fails in Vista - after reading through many forums, I'm still at a loss why Vista handles this differently then XP.
What I'm attempting to do is pass a variable, in this case Servicepack, and then act on that variable. However, Vista always returns the variable is unexpected at this time after the FOR /F call.

The Code is simply:

:: Look for .NET 2.0 SP1

Reg QUERY "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" /v SP >NUL


FOR /F "TOKENS=3 DELIMS= " %%A IN ('REG QUERY "HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727" /v SP') DO (SET SP=%%A)


Again, works great in XP, in vista is fails. Doesn't matter the key - I have the same problem checking currentversionbuild in the registry - each time it will prompt back with <variable> is unexpected at this time. Any help is appreciated.

See More: 0x0 was unexpected at this time

Report •

September 10, 2009 at 16:00:53
On Vista, for some reason, the FOR /F statement results in zero iterations, so SP is never set. The last line therefore reads:


so 0x0 was indeed unexpected.

Why doesn't the FOR /F loop execute? My guess is that you use the tab character for delimiters. The REG command uses tabs in its output on XP, but spaces on Vista. Since you have tokens=3 it doesn't find the 3rd field, because there are no tab delimiters in REG's output.

Report •

September 10, 2009 at 16:52:57
Two guesses:

1) That key does not exist in Vista's registry.

2) The behavior of REG changed, and it no longer sends its output to STDOUT.

Report •

September 11, 2009 at 02:04:36
Razor, you are right in pointing out the possibility of the key not existing on Vista. But point 2, the behaviour of REG has changed, but it still sends its output to STDOUT. It also looks identical, but it uses spaces instead of tabs to delimit the fields in the string "valueName REG_SZ value data". Therefore if you use for /f "delims=<tab>" it will no longer work.

The developers of REG.exe for Vista must have been having mischievous thoughts when they changed its behaviour, such that it uses spaces up to the next 8-column tab stop to fool you into thinking it uses tabs like it did before.

Report •

Related Solutions

September 11, 2009 at 09:08:41
klint - you were correct on that one..Great JOB...I actually tried to use delims' with spaces and it still didn't work - so I removed the entire delim reference and it returned the exact field I needed. All my searching yesterday and no one referenced that the delim's had changed with Vista - another reason to um. errr..."love" Vista - Virtual Cold Beer for ya - Thanks again~~!

Report •

Ask Question