Dynamically assigned environmental variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchfileman
Posts: 16
Joined: 07 Jun 2010 10:27

Dynamically assigned environmental variables

#1 Post by batchfileman » 07 Jun 2010 13:18

The remote part is not the issue it is testing the variables that were just created.

As an example when I run the batch file you created above I get:

userVar1=Administrator
userVar4=All Users
userVar5=Default User
userVar6=LocalService
userVar7=NetworkService
userVar8=setup
userVar9=mainuser1
userVar10=mainuser2
userVar11=mainuser3
Press any key to continue . . .


What I would like to do is test these variables to weed out everything except "userVar9" or "mainuser1" ; "userVar10" or "mainuser2" ; "userVar11" or "mainuser3".

I could have three users as in this example or 100. I want to run a specific task for each user but not the admin and setup users.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Dynamically assigned environmental variables

#2 Post by aGerman » 07 Jun 2010 13:52

You could write something like a black list:

blacklist.txt

Code: Select all

Administrator
All Users
Default User
LocalService
NetworkService
setup

This is case sensitive.

Now you could use this:

Code: Select all

@echo off &setlocal
pushd "C:\Documents and Settings"
for /f "delims=: tokens=1*" %%a in ('dir /ad /b^|findstr /v /x /g:"%~dp0blacklist.txt"^|findstr /n .') do set "userVar%%a=%%b"
popd

:: display all
set userVar
pause


Regards
aGerman

Post Reply