Greg`s Tech blog

Logon script

Thursday 27 of March, 2008
More on the corporate logon script.

So here's the final script. There is a lot going on because we're trying to think ahead and be prepared for various user & corporate needs. We based this on a script from one staffers previous job. Had we started from scratch, we would have a slightly lighter script, but would invest more time later solving problems.

Note the use of '::' as a comment lead in (as opposed to REM) for easier readability.

:: *******************************************************************************
:: This is the default Somecorp Windows Login batch file.
:: Modifications
:: 3/17/08 GjM Original script
:: 3/26/08 GjM Moved personal script to end; cleanup
:: 3/26/08 GjM Added setdrive.cmd to unmap then remap drives
:: 3/26/08 GjM Added test to see if were logging into a server.

:: *******************************************************************************
:: Change title of window for NT machines
echo Please wait while your logon is processed...

:: *******************************************************************************
:: ********************* Set a temporary path for executables. ************************
:: ********************* Used only during logon process. *************************
SET PATH=\\somecorp.com\sysvol\somecorp.com\scripts\bin;%PATH%
SET LOGONBIN=\\somecorp.com\sysvol\somecorp.com\scripts\bin
SET USERLOGONBIN=\\somecorp.com\sysvol\somecorp.com\scripts\users

:: Test to see if we should run this script
cscript /nologo %LOGONBIN%\Groupcheck.vbs "MigratedUsers"
if %errorlevel% EQU 0 (
   echo Failed groupcheck, exiting...
   Goto :EOF

:: Test to see if we are on a server and shouldn't run
cscript /nologo %LOGONBIN%\IsServerOS.vbs
if %errorlevel% EQU 0 (
   echo Running on a server; skipping logon script!
   Goto :EOF

goto Main

:: *******************************************************************************
:: **************** Look for LOGONSERVER and reset if necessary ******************
:: **************** This may be necessary if user logins in off net and joins later
:: **************** Ex: mobile user VPNS and runs script to map drives ***********
:: Check for LOGONSERVER var reset for logon process if necessary for remote access
:: CScript %LOGONBIN%\RegWrite.vbs "HKEY_CURRENT_USER\Volatile Environment\LOGONSERVER" \\server REG_SZ

:: **********************************************************
:: Map Corporate shares
call setdrive H \\somecorp.com\Corp\All_HomeDIR\%username%
call setdrive I \\somecorp.com\Corp
call setdrive J \\somecorp.com\Tech
call setdrive K \\somecorp.com\Prod

:: ********************* Look for and run personal logon script ******************
@echo Checking for Personal Logon script...

If exist %USERLOGONBIN%\%username%.cmd (
	@echo Found personal login script
	call %USERLOGONBIN%\%username%.cmd

::A real personal login script...
::This is a Netadmin secret (shhh!)
@if exist c:\local\mylogon.bat call c:\local\mylogon.bat

:: *******************************************************************************
:: ************** Inventory Plus REMd out on 013001 by bsc ***************
:: echo %DATE% %TIME% "Starting Inventory Select: " /n
:: INVselect.vbs abcdefg

:: ********************************************************************************
:: **************************** Launch homepage ********************************
::************************** Added 03/22/02 BSC ********************************
::start http://www.somecorp.com

There are calls to several external scripts

These scripts are documented elsewhere in this blog

As with all this, use it if it helps.