Question

Locked

How to create a batch file for same user depending on computer logged in?

By MGA-Saande ·
We have a user that will currently work in two different sections of our building and depending on where he is working or logged in, he will get some shared folders.

That user will work on specific computers on side A and B of the building.

Is there a way I could tell the script to create specific shared folders, depending on which computer the user is logging unto?

Thanks,

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

One Possible Batch File

by Vallum Halo In reply to How to create a batch fil ...

You have to have some way to determine whether the computer is on side A or side B of the building.

One way to do that would be to just hard-code in a list of computers, and check the standard Windows %COMPUTERNAME% environmental variable.

Here is an old-time Windows batch file that should do the trick. It could definitely be improved on (for example the computer names are all case sensitive.) You list the computers in Side A and Side B, then add commands at the :CONFIGURE_SIDE_A and :CONFIGURE_SIDE_B labels below.

REM:::::::::::::::::::::::::::::::::::::::::::::::::::::

REM: These computers are on side "A"

if %COMPUTERNAME% == WINDOWS1 goto CONFIGURE_SIDE_A
if %COMPUTERNAME% == WINDOWS3 goto CONFIGURE_SIDE_A
if %COMPUTERNAME% == WINDOWS5 goto CONFIGURE_SIDE_A
if %COMPUTERNAME% == WINDOWS7 goto CONFIGURE_SIDE_A

REM: These computers are on side "B"

if %COMPUTERNAME% == WINDOWS2 goto CONFIGURE_SIDE_B
if %COMPUTERNAME% == WINDOWS4 goto CONFIGURE_SIDE_B
if %COMPUTERNAME% == WINDOWS6 goto CONFIGURE_SIDE_B
if %COMPUTERNAME% == WINDOWS8 goto CONFIGURE_SIDE_B
if %COMPUTERNAME% == WINDOWSA goto CONFIGURE_SIDE_B
if %COMPUTERNAME% == WINDOWSC goto CONFIGURE_SIDE_B

REM: No match for any computer. Handle the error.

GOTO HANDLE_ERROR

REM: These are executed for computers on Side A

:CONFIGURE_SIDE_A
REM: Insert configuration commands for Side A
GOTO EXIT

REM: These are executed for computers on Side B

:CONFIGURE_SIDE_B
REM: Insert configuration commands for Side B
GOTO EXIT

:HANDLE_ERROR
echo No match for device %COMPUTERNAME%

:EXIT
echo Finished.

REM:::::::::::::::::::::::::::::::::::::::::::::::::::::

As I say above, it could definitely be improved upon, but at least this should give you a reasonable approach. You might be able to test against something other than the computer name, such as if there is some file on "Side A" platforms that doesn't exist on "Side B" platforms. (That would greatly simplify things in the batch file.)

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums