Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: IF %username%== ... looking to compare more than 1 at a time  (Read 17477 times)

0 Members and 1 Guest are viewing this topic.

giarc9

  • Guest
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.

devcom



    Apprentice

    Thanked: 37
    Re: IF %username%== ... looking to compare more than 1 at a time
    « Reply #1 on: May 12, 2009, 12:57:50 PM »
    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


    Download: Choice.exe

    giarc9

    • Guest
    Re: IF %username%== ... looking to compare more than 1 at a time
    « Reply #2 on: May 14, 2009, 06:54:18 AM »
    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