Set an Environment Var from the output of a program

M

M.Siler

I have a program called nbmac.exe (http://www.kostis.net/freeware/nbmac.zip)
that will give you the MAC of your workstation. I'm wanting to take this
output and set an environment variable but I can't seem to figure out how?

FYI - Here's what I'm trying to do overall: We are setting up roaming
profiles and the problem is when a use sits a some other workstation they
aren't mapped to correct network printer. Therefore I want to write a logon
script that sets the MAC address in an environment variable so I can run it
through a list if IF statements so I can map specific machines to specific
network printers. Make sense?
 
D

David Candy

echo. |date>date.txt
FOR /F "eol=E tokens=4,5,6,7,8* delims=/, " %%i in (date.txt) do Set Z=%%k-%%l-%%m

Here I set Z to the date by parrsing a text file with the date in it.

See help.
 
C

Chuck

I have a program called nbmac.exe (http://www.kostis.net/freeware/nbmac.zip)
that will give you the MAC of your workstation. I'm wanting to take this
output and set an environment variable but I can't seem to figure out how?

FYI - Here's what I'm trying to do overall: We are setting up roaming
profiles and the problem is when a use sits a some other workstation they
aren't mapped to correct network printer. Therefore I want to write a logon
script that sets the MAC address in an environment variable so I can run it
through a list if IF statements so I can map specific machines to specific
network printers. Make sense?

nbmac >c:\mac.txt
for /f "tokens=*" %%z in (c:\mac.txt) do call :parseMAC %%z
goto :EOF
:parseMAC
set MyMac=%1
:EOF

Looking at the contents of c:\mac.txt, I'd bet that the whole thing could be
done with a pipe, in a single command. I think. I just have to hunt thru some
of my libraries a while.

Cheers,
Chuck
Paranoia comes from experience - and is not necessarily a bad thing.
 
C

Chuck

I have a program called nbmac.exe (http://www.kostis.net/freeware/nbmac.zip)
that will give you the MAC of your workstation. I'm wanting to take this
output and set an environment variable but I can't seem to figure out how?

FYI - Here's what I'm trying to do overall: We are setting up roaming
profiles and the problem is when a use sits a some other workstation they
aren't mapped to correct network printer. Therefore I want to write a logon
script that sets the MAC address in an environment variable so I can run it
through a list if IF statements so I can map specific machines to specific
network printers. Make sense?

Dohh.

From command line:
for /f "tokens=*" %z in ('nbmac') do set MyMAC=%z
Part of script file:
for /f "tokens=*" %%z in ('nbmac') do set MyMAC=%%z

Cheers,
Chuck
Paranoia comes from experience - and is not necessarily a bad thing.
 
C

Chuck

Very Nice... Not sure I completely understand, but thank you!

The author of "nbmac" made it so clean - it outputs just the MAC address - no
headers or extraneous text. So it's easy to just use the "for" command in one
pass.

The "date" command isn't so easy - it puts out two lines of text, PLUS it asks
for input ("Enter new date:"). So that involves at least 2 lines of code, plus
a temporary file. As David wrote.

Extracting the date with "date /t" makes this possible:
for /f "tokens=1,2,3,4* delims=/, " %i in ('date /t') do set MyDate=%j/%k/%l
I'm not sure how available the "/t" parameter is though.

It's fun writing this stuff - almost as arcane as Assembler language.

Thanks for the link to "nbmac" - I'm curious if the author has any other nice
utilities like that.

Cheers,
Chuck
Paranoia comes from experience - and is not necessarily a bad thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top