• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

If Statement in Login Script

I am attempting to set a default network printer in our login script based upon the username. I have added the following code to our script, but regardless of the value that I place to the right of the == sign, the command in :SetDefault processes. What am I missing?

if %USERNAME%==TEST goto :SetDefault
 
:SetDefault
@Rundll32.exe printui.dll,PrintUIEntry /in /y /q /n"\\whv-vm6\litigation-copy"
exit
0
MAThornton
Asked:
MAThornton
  • 2
  • 2
1 Solution
 
oBdACommented:
You need to turn on case insensitive comparison:
if /i %UserName%==TEST goto SetDefault
0
 
Gerald26Commented:
TEST is uppercase, i think you are login in lowercase
You are not doing anything else if test fails, add a GOTO END

replace with

echo %username% | find /i "test" || goto :End
:SetDefault
@Rundll32.exe printui.dll,PrintUIEntry /in /y /q /n"\\whv-vm6\litigation-copy"
:End
exit
0
 
oBdACommented:
Oh, and you need of course a "goto :eof" after the "if" statement, sorry:
if /i %USERNAME%==TEST goto SetDefault
goto :eof
:SetDefault
@Rundll32.exe printui.dll,PrintUIEntry /in /y /q /n"\\whv-vm6\litigation-copy"
exit

Open in new window

0
 
Gerald26Commented:
f /i %USERNAME%==TESTis actually more accurate than find /i "test" (because test2 would also return true)

Use oBdA solution.
0
 
MAThorntonAuthor Commented:
This worked. Thanks for your help.

Mark
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now