Computing.Net > Forums > Programming > for /f tokens and wmic command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

for /f tokens and wmic command

Reply to Message Icon

Name: tentmakeroz
Date: October 21, 2009 at 18:14:47 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: Batch
Comment:

Hi all
Great site this, very valuable help:

rem **mybatch file**
set /P IPHOST=Please enter the HOSTNAME or IP address of the Computer:
echo IP address is %IPHOST%

WMIC /NODE: %IPHOST% COMPUTERSYSTEM GET NAME > rhost.txt
rem set /p remhost= < rhost.txt ***not using***
WMIC /NODE: %IPHOST% COMPUTERSYSTEM GET USERNAME > wmic.txt
rem set /p USRID= < wmic.txt ***not using***
more rhost.txt
more wmic.txt
echo.

FOR /F "skip=1" %%A in (rhost.txt) DO set rhost=%%A
FOR /F "skip=1" %%C in (wmic.txt) DO set USR=%%C

echo %IPHOST% %rhost% %USR%
rem **end**

I am expecting it to display IPaddress Hostname Username
but all I get it is IPaddress
and the other two are blank

Any ideas?



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 22, 2009 at 02:15:36 Pacific
Reply:

Post the contents of rhost.txt and wmic.txt so we can correct the For /F parsing statements.


0

Response Number 2
Name: tentmakeroz
Date: October 22, 2009 at 20:09:33 Pacific
Reply:

HI IVO

I worked out that it was the text files created by the WMIC command wouldn't parse. (maybe trailing spaces or LF or CR character - don't know)

I worked out I only had to run the command once and get both variables.
I had to then output it to another text file and parse that

WMIC /NODE: %IPHOST% COMPUTERSYSTEM GET NAME, USERNAME > wmic.txt
type wmic.txt >pcinfo.txt
echo.

FOR /F "skip=1" %%G in (pcinfo.txt) DO set rhost=%%G
FOR /F "skip=1 tokens=2" %%H in (pcinfo.txt) DO set usr=%%H

Output of both files looked identical
Name UserName
MYPCNAME MYUSERID

I am modifying it a bit more, and will post it when finished (minus any company specific info of course)

Thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


iTunes VBS or Perl script copy files from folder A ...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: for /f tokens and wmic command

for /f tokens and delims help www.computing.net/answers/programming/for-f-tokens-and-delims-help/20076.html

How to break/exit FOR /F in DOS www.computing.net/answers/programming/how-to-breakexit-for-f-in-dos/15269.html

Batch Help: findstr use in for /f www.computing.net/answers/programming/batch-help-findstr-use-in-for-f/16005.html