You are not logged in.

#1 26 Jan 2015 12:43

neodoughnut
New Member
Registered: 28 Mar 2014
Posts: 4

WMIC Registry Retrieval in FOR LOOP!

Guys,

I have a script which needs to use the following line below, which by itself works correctly and returns the result expected:

wmic /user:.\Administrator /password:Password /NODE:PC01 /namespace:\\root\default class stdregprov call GetStringValue sSubKeyName="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI" sValueName="LastLoggedOnUser"')

but when use in a FOR LOOP such as the one below:

FOR /F "tokens=1 delims=" %y in ('wmic /user:.\Administrator /password:Password /NODE:PC01 /namespace:\\root\default class stdregprov call GetStringValue sSubKeyName="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI" sValueName="LastLoggedOnUser"') DO echo %y

It returns:

Invalid format.
Hint: <paramlist> = <param> [, <paramlist>].


Any ideas guys?

smile

Cheers

Steve

Offline

#2 26 Jan 2015 16:40

DigitalSnow
Member
From: United States
Registered: 27 Dec 2012
Posts: 24

Re: WMIC Registry Retrieval in FOR LOOP!

Surround the entire command with double quotation marks and remove the internal double quotation marks since there are no spaces you have to worry about.  I am not sure of the exact cause without looking into it further, but off hand it appears that when for parses the command it is separating it and causing the command not to get all the parameters at once.

for /f "delims=" %A in ('"wmic /namespace:\\root\default class stdregprov call GetStringValue sSubKeyName=SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI sValueName=LastLoggedOnUser"') do @echo %A

Offline

Board footer

Powered by