|
Answer» Hello,
Typically I don't have trouble finding a good WAY to execute this stuff in a batch file (USUALLY I search the HECK out of this site & OTHERS), but this one is confusing me a bit & I can't find many examples that are clicking for me today.
I have a good number of users I need to detect in a batch file (my list has ~20 users). Based on the username or usernames, I want to execute net use drive mappings.
Typically I'd just make a unique batch file for each user, but the number of users I have keeps climbing & I'd like to start maintaining just 1 batch file for the whole list of users.
Here's what I've come up with so far when there's only 1 user in a group:
Code: [Select]IF [NOT] "%username%"=="JohnDoe" GOTO NEXT1 @net use J: /delete @net use J: "\\Not JohnDoe's Home Folder" /no GOTO ENDIF
:NEXT1 IF [NOT] "%username%"=="JaneDoe" GOTO NEXT2 @net use J: /delete @net use J: "\\Not JaneDoe's Home Folder" /no GOTO ENDIF
:NEXT2 <repeat thru list of users>
:ENDIF
This should work fine, but it rapidly increases the number of lines in the file. What I'd like to do is compare a group of people in 1 shot. Something like:
Code: [Select]IF [NOT] "%username%"=="JohnDoe" OR "JaneDoe" OR "FredDoe" GOTO NEXT1 @net use K: /delete @net use K: "\\Folder that all 3 users store files in" /no GOTO ENDIF
:NEXT1 IF [NOT] "%username%"=="VIP1" OR "VIP2" OR "VIP3" GOTO NEXT1 @net use K: /delete @net use K: "\\Folder that only VIP users store files in" /no GOTO ENDIF
:NEXT2 <and so on and so forth>
:ENDIF
If it exists, does anyone have the correct syntax I should use to compare a group of usernames in this manner? Please let me know if I can clarify anything.Code: [Select]IF NOT "%username%" equ "JohnDoe" set /a num+=1 IF NOT "%username%" equ "JaneDoe" set /a num+=1 IF NOT "%username%" equ "FredDoe" set /a num+=1
if %num% equ 3 goto NEXT1
Works just fine - THANKS!
I did run into the problem of the %username% containing upper case characters & that throws things off a bit. I.E. JohnDoe != johndoe
Next challenge up!
*edit*
Easy enough...
Code: [Select]IF /i NOT "%username%"=="JohnDoe" GOTO NEXT1
|