Page 1 of 1

Dynamically assigned environmental variables

Posted: 07 Jun 2010 13:18
by batchfileman
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.

Re: Dynamically assigned environmental variables

Posted: 07 Jun 2010 13:52
by aGerman
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