Page 1 of 1
Dynamically assigned environmental variables
Posted: 07 Jun 2010 10:31
by batchfileman
I am looking to write a batch file that will take the usernames out of the directory "C:/Documents and Settings/****" and store them in environmental variables.
I then want to be able to then call each of these variables individually. For example I may want # 50 but not 39-43. I am designing the logic behind that but cannot get the variables to store the way I want. Any suggestions?
Re: Dynamically assigned environmental variables
Posted: 07 Jun 2010 10:49
by aGerman
Try this
Code: Select all
@echo off &setlocal
pushd "C:\Documents and Settings"
for /f "delims=: tokens=1*" %%a in ('dir /ad /b^|findstr /n .') do set "userVar%%a=%%b"
popd
:: display all
set userVar
pause
Regards
aGerman
Re: Dynamically assigned environmental variables
Posted: 07 Jun 2010 12:23
by batchfileman
So this works to put each of the usernames into a variable. Now why can I not reference them.
For example I cannot "echo userVar7" and get the seventh entry.
Re: Dynamically assigned environmental variables
Posted: 07 Jun 2010 12:25
by batchfileman
DOH! I'm a butt. echo %userVar7%. All set here. You are wonderful. Thank you my german friend.
Re: Dynamically assigned environmental variables
Posted: 07 Jun 2010 12:49
by batchfileman
What about testing the variables dynamically. For example I am on a domain network. I am looking specifically to remove an icon that has been placed on individual users desktops. I do not really care about the administrator, localservice, setup etc... users. However some machines only have one user and some have hundreds. Any good way to do that?
Re: Dynamically assigned environmental variables
Posted: 07 Jun 2010 13:03
by aGerman
No, sorry. I've no idea how to do this remotely.
Regards
aGerman