Computing.Net > Forums > Programming > Pipe Find resultes to Variable..m2

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.

Pipe Find resultes to Variable..m2

Reply to Message Icon

Name: x2aberry
Date: October 23, 2009 at 05:48:24 Pacific
OS: Windows XP
CPU/Ram: 2g
Product: Microsoft Windows xp professional w/service pack 3
Subcategory: Batch
Comment:

Ok First, This is what I am ultimatly trying to do....

Create a batch file that will..

1- take a computername and resolve the ip on the domain using NSlookup.

2-take that ip and extract the first 3 octs into a variable.(example: out of 192.168.1.50, I just want [192.168.1.] as the variable.

3- starting from 2 attempt to quickly ping the ip to see if it is being used (example:[192.168.1.] 2 )

4- if 2 is not online goto next number (3) and so forth until it finds a PC online.

5- when a pc is found run the following command to see if anyone is logged in.
----------------------
wmic /node:%cp% PROCESS where "caption='explorer.exe'" getowner | find "User = "
--------------------------
6-Using the above command, somehow determine in command prompt if user is logged in or not.

7- if somone IS logged in, procced to ping the next PC (4) and so forth until find another one that is on and that nooone is logged into.

8-put the ip address of the avalible PC that noone is logged onto into a variable %sevrer%
=========================

So right now
So far i can use the wmic command piped with FInd to display the user name if someone IS logged in. But I can't figure out how to strip the output to just the user name. This is the output I usually get:
------------------------------------------
User = "27berry";
User = "27berry";
------------------------------------------
Notice the duplicate. and the wasted space and the "User = " part.
i just cant seem to figure out how to strip it down.

any thoughts?


sorry if its kind of confusing..
Thanks if you guys have any ideas.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 24, 2009 at 06:38:57 Pacific
Reply:

wmic /node:%cp% PROCESS where "caption='explorer.exe'" getowner | find "User = " > out.txt
for /F "tokens=2 delims==" %%j in (out.txt) do set _user=%%j
del out.txt
set _user=%_user:"=%
set _user=%_user:~1,-1%


0
Reply to Message Icon

Related Posts

See More


Dos command? File I/O counting number ...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Pipe Find resultes to Variable..m2

for loop find result into variable www.computing.net/answers/programming/for-loop-find-result-into-variable/20281.html

shell script to obtain login ip adr www.computing.net/answers/programming/shell-script-to-obtain-login-ip-adr/5661.html

Piping file count into variable www.computing.net/answers/programming/piping-file-count-into-variable/19046.html