Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bacth file logon script tests for %username% 3

Status
Not open for further replies.

spikestik

IS-IT--Management
Jan 28, 2003
59
US
I am having trouble accomplishing the following:
I want the following Logon Script to execute and test for the logon
user.
If it is the Administrator I want the script to end and not map drive.
If it is another user than I want the script to continue. Can someone
please look at this and tell me what I am doing wrong?

Thank you

@echo off

REM Welcome Screen
echo *********************************************************************
echo * Please wait as the %username% is authenticated.
echo * You are accessing the network from %COMPUTERNAME%
echo * And you are running the %OS% os.
echo * Hello %USERNAME%, welcome to the network!
echo *********************************************************************

REM Set Network Time
net time \\abc /set /yes

REM Disconnect Existing Network Drive Connections
net use * /delete /yes

REM Test For Administrator
IF "%USERNAME%" == "Administrator" GOTO END
IF "%USERNAME%" == "" GOTO Drives

REM Connect Network Drives
net use /persistent:yes

:Drives
net use M: \\abc\APPS
net use N: \\abc\Pub
net use x: \\abc\USERS\%UESERNAME%

:END
 
Remove the second IF statemnet...

Code:
@echo off

REM Welcome Screen
echo *********************************************************************
echo * Please wait as the %username% is authenticated.
echo * You are accessing the network from %COMPUTERNAME%
echo * And you are running the %OS% os.
echo * Hello %USERNAME%, welcome to the network!
echo *********************************************************************

REM Set Network Time
net time \\abc /set /yes

REM Disconnect Existing Network Drive Connections
net use  * /delete /yes

REM Test For Administrator
IF "%USERNAME%" == "Administrator" GOTO END
ECHO You aren't the administrator
GOTO Drives

:Drives
net use M: \\abc\APPS
net use N: \\abc\Pub
net use x: \\abc\USERS\%UESERNAME%

:END
ECHO Finished login script.
 
baddos

thank you for the information. i tried the above posting and what i found was that the script executed but it executed the same for all users.

any thoughts?
 
Whoa... I missed this...

IF "%USERNAME%" == "Administrator" GOTO END

should be

IF %USERNAME% == Administrator GOTO END
 
For some strange reason...this still processes every line no matter what the username is.

someone please help.
 
when logging in are you Administrator or administrator
I'm pretty sure what you are testing for is case sensitive.
 
You don't specify which client OS you are testing this against. If it is Windows 95/98 it won't work, because they don't have the USERNAME variable.
 
Usernames are not case sensative.
Good point Crobin1 ..... 2k accross the board.
 
Usernames in batch files are case sensitive. I tested it. There is my test file (my username on this computer was case sensitive 'KarlisI'):
===========
@echo off
if %USERNAME% == karlisi goto NCS
if %USERNAME% == KarlisI goto CS
goto END

:CS
echo %USERNAME% Case sensitive
goto END

:NCS
echo %USERNAME% Not case sensitive
goto END

:END
=====================
Output was:

D:\>D:\test.bat
KarlisI Case sensitive

D:\>


===
Karlis
ECDL; MCP
 
Thank you Karlisi.
I dont believe it's the username that is case sensitive. It is that you are testing for a variable. (A does not = a)
 
damion68, you are right, usernames are not case sensitive, variables are case sensitive. In this script it is the problem, I believe.

===
Karlis
ECDL; MCP
 
Thank you all for your input...a real eyeopener.
 
Try this:

REM Welcome Screen
echo *********************************************************************
echo * Please wait as the %username% is authenticated.
echo * You are accessing the network from %COMPUTERNAME%
echo * And you are running the %OS% os.
echo * Hello %USERNAME%, welcome to the network!
echo *********************************************************************

REM Set Network Time
net time \\abc /set /yes

REM Disconnect Existing Network Drive Connections
net use * /delete /yes

REM Test For Administrator
IF NOT "%USERNAME%"=="Administrator" GOTO drives
GOTO end

:drives
net use M: \\abc\APPS /persistent:yes
net use N: \\abc\Pub /persistent:yes
net use x: \\abc\USERS\%USERNAME% /persistent:yes
GOTO end

:end
exit

Slight change in logic but it is similar to what I use for logons on our domain.
 
Further info -
1) Copy and paste my script as I did some "space" removal. As I think some of the problem may have been the spaces around the == signs.
2) Drives mapped via a logon script are persistant by default so you should not need the /persistant:yes switch.
In fact if you use /persistant:no you can remove the line net use * /delete /yes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top