[Samba] login scripts --what to use

Chris Smith smb_77 at chrissmith.org
Thu Jun 19 18:18:45 GMT 2008


On Thursday 19 June 2008, Christopher Perry wrote:
> We're setting up a PDC, and would like to have a login script to
> deliver the mapped drives to users in particular groups, and connect
> to printers. The printer drivers come from the [print$], share.
>
> Does anyone have any good resources for this? What's the easiest and
> simplest thing to get going --vbscript or batch files?

I use a monolithic bat file that works, outside of installing printers 
in non-NT based systems. It could be simplified in at least two ways: 
1 - if you have no need to support pre-NT based winboxen, and 2 - use a 
separate script for each user instead of the monolithic format (just 
been using it for years, even with NT PDC's).

Example:
=====================================================
@echo OFF
@if not "%ECHO%"=="" echo %ECHO%
set NETSW=/yes
if "%OS%"=="Windows_NT" set NETSW=/persistent:no %NETSW%
if exist l:*.* net use l: /delete
net use l: \\server\library %NETSW%
if exist p:*.* net use p: /delete
net use p: \\server\projects %NETSW%
rem acct shares
if "%USERNAME%"=="dave" goto :ACCTSET
if "%USERNAME%"=="frontdesk" goto :ACCTSET
if "%USERNAME%"=="keith" goto :ACCTSET
goto :ACCTSKIP
:ACCTSET
if exist w:*.* net use w: /delete
net use w: \\server\ad2 %NETSW%
if exist o:*.* net use o: /delete
net use o: \\server\office %NETSW%
:ACCTSKIP
rem additional office shares
if "%USERNAME%"=="buster" goto :OFFICESET
if "%USERNAME%"=="george" goto :OFFICESET
goto :OFFICESKIP
:OFFICESET
if exist o:*.* net use o: /delete
net use o: \\server\office %NETSW%
:OFFICESKIP
rem acct shares
if not "%OS%"=="Windows_NT" goto :PRT
rundll32 printui.dll,PrintUIEntry /dn /n "\\server\Virtual_Printer" /q
rundll32 printui.dll,PrintUIEntry /dn /n "\\server\konicaC450" /q
rundll32 printui.dll,PrintUIEntry /dn /n "\\server\hpLaserJet" /q
rundll32 printui.dll,PrintUIEntry /in /n "\\server\Virtual_Printer" /q
rundll32 printui.dll,PrintUIEntry /in /n "\\server\konicaC450" /q
rundll32 printui.dll,PrintUIEntry /in /n "\\server\hpLaserJet" /q
if "%COMPUTERNAME%"=="COMP1" goto :DEFPRN
if "%COMPUTERNAME%"=="COMP4" goto :DEFPRN
if "%COMPUTERNAME%"=="COMP9" goto :DEFPRN
if "%COMPUTERNAME%"=="COMP12" goto :DEFPRN2
if "%COMPUTERNAME%"=="COMP16" goto :DEFPRN2
goto :EOF
:DEFPRN
rundll32 printui.dll,PrintUIEntry /y /n "\\server\hpLaserJet" /q
goto :EOF
:DEFPRN2
rundll32 printui.dll,PrintUIEntry /dn /n "\\server\acctPrt" /q
rundll32 printui.dll,PrintUIEntry /in /n "\\server\acctPrt" /q
rundll32 printui.dll,PrintUIEntry /y /n "\\server\acctPrt" /q
goto :EOF
:PRT
if exist h:*.* net use h: /delete
net use h: \\server\%USERNAME% %NETSW%
net time /set /yes
if exist c:\windows\*.* echo . >c:\windows\lmscript.$$$
=====================================================

You'll notice that I delete shares/and printers before adding them. This 
takes a few extra seconds but prevents warnings/errors being raised 
when trying to map/connect to existing shares. Also if a user deletes a 
printer or share they simply have to logoff and logon to get it back.

The "net time" command is not run for NT based systems as the users do 
have rights to set the time and the W32time service works continuously 
and better anyway.

The h: drive is the "home" drive which gets set automagically in 
NT-based boxen but not in the others.

-- 
Chris


More information about the samba mailing list