Configuring Batch file.

Microsoft Windows xp professional w/sp2
March 2, 2010 at 06:45:58
Specs: Windows XP, 1 GB
Hye,

I am using Windows Xp, and I want to create a batch file for running different program for different users.
I have four users, and I placed the shortcut of batch file on the desktop of each user. I want to use
one batch file and I want to use if command with AND / OR, but I do not know the syntax, I have read posts about
if command but I am unable to understand how can I create the batch file. Below is the example of batch file which I want
to create, needs to be modified.

( if %USERNAME% == user1 run c:\Program1.exe,
if %USERNAME% == user2 run C:\Program2.exe,
if %USERNAME% == user3 run c:\Program3.exe,
if %USERNAME% == user dont run any program and show a message, that "batch file will not run if you're logged in as user" )


Waiting for response, Thanks...


See More: Configuring Batch file.

Report •

#1
March 2, 2010 at 13:41:06
one way is to put the user's into the script, another way is to make a script for each user and call that script from the main script. this seems cleaner than using all those "IFs".
method one, main login script:
goto :%username% 2>nul
echo %username% has not been set up!
goto :eof
:joe
excel wksht1
goto :eof
:bob
wp.exe mydoc
goto :eof
:user
echo generic user no batchfile will be run. bye
goto :eof
----------------------- end
::method two, main login script:
set xx=%username%
%xx% 2>nul
echo no user script has been set up for %xx%
------------------- end
::(joe.bat - Joe's login script)
echo hello %0
pause
excel wksht1
goto :eof
----------------- end

Report •

#2
March 2, 2010 at 23:45:38
Hello nbrane,

Thanks for replying, Thats great, & Please help me in the following batch file. As there are five users in my computer, so I want to map a drive to all other users except user1 and user2, but the problem is this, i dont know how to use multiple ifs. I created batch file...(needs to be modified)

( @echo off
if %USERNAME% == user1 goto YSKIP
if %USERNAME% == user2 goto YSKIP
NET USE Z: \\Server\Files
goto END
:YSKIP
:END )

But the problem is user1 does not see any mapped drives as the batch file run successfully, but user2 see the z drive, so I want to use multiple if command but i dont know the syntax.

Thanks again...


Report •

#3
March 3, 2010 at 00:34:18
it looks like it should work. only small things might be problems, but i doubt, but try these suggestions:
put quotes around the items and take spaces out:

@echo off
if "%USERNAME%"=="user1" goto :YSKIP
if "%USERNAME%"=="user2" goto YSKIP
NET USE Z: \\Server\Files
goto :END
:YSKIP
:END
::------------ end script

use echos of var.s, and pauses to see what's going on.
H.t.h


Report •

Related Solutions

#4
March 4, 2010 at 05:45:03
Hello nbrane,

Well thanks it worked, but I didnt understand the following line

"use echos of var.s, and pauses to see what's going on"

And you know how to use multiple ifs? If yes, please tell me.

Thanks...


Report •

#5
March 4, 2010 at 12:48:49
if it's working, you don't need to worry about "use echos..." etc., that was just for debugging the script.
There's not much about IF i can add to what you already know. at commandline, c:> type: IF /?
to get more information.
you can stack IFs, and you can nest IFs:
if blah1 if blah2 echo true
will echo "true" only if both IFs are true.
IF blah1 (
IF blah2 (
echo "both true"
) else (
echo "blah1 true, blah2 not"
) else (
echo blah 1 not true, blah 2 not tested, unknown
)
or successive IFs:
if blah1 (echo blah1 true) else (echo blah1 false)
if blah2 (echo blah2 true) else (echo blah2 false)
you prob'ly get the idea by now. good luck

Report •

Ask Question