[Samba] login scripts --what to use

Dennis McLeod dmcleod at foranyauto.com
Thu Jun 19 16:31:04 GMT 2008

> -----Original Message-----
> From: samba-bounces+dmcleod=foranyauto.com at lists.samba.org 
> [mailto:samba-bounces+dmcleod=foranyauto.com at lists.samba.org] 
> On Behalf Of Christopher Perry
> Sent: Thursday, June 19, 2008 7:14 AM
> To: samba at lists.samba.org
> Subject: [Samba] login scripts --what to use
> Hi,
> 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?
> Thanks,
> chris

I use bat files, because I'm not smart enough to figure out vbscript.....
I'm posting this because I get a lot of help here, but rarely can help
anyone. I am better at windows than *nix, but I'm trying to learn...
There is MORE here than you asked for, but maybe someone else can use
Please, don't tease.....

Here's my logon script which calls a bunch of others.



@echo on
set logondrive=\\server\netlogon\scripts
set software=p:\software
set logs=\\server\logs

ECHO Login - %username% - %date% - %time% >> "%logs%\%computername%.txt"
CALL %logondrive%\drives.bat
CALL %logondrive%\O2K7fmt.bat
CALL %logondrive%\pfbk.bat
CALL %logondrive%\dns.bat
CALL %logondrive%\filecopy.bat
CALL %logondrive%\favorites.bat
CALL %logondrive%\flash9.bat
CALL %logondrive%\java.bat
CALL %logondrive%\ar707.bat
CALL %logondrive%\svg.bat
CALL %logondrive%\ldap.bat
Call %software%\mozilla\firefox\ffxupdate.bat
CALL %logondrive%\stats.bat
CALL %logondrive%\wsusupdate.bat
cscript p:\printers.vbs


The "%logs% folder is writeable, but not readable. You can look at the
folder (if you knew where), but it appears there is nothing in there.
Only root can look at the files in there...
There was a series of posts earlier this year on how to make one.
( http://lists.samba.org/archive/samba/2008-April/139726.html ) 
I think that's the pertinent post.

Drives.bat maps drives.
O2K7fmt installs the Office 2007 file format converters...
Pfbk.bat installs Microsoft's pst backup utility for Outlook.
Dns.bat sets the DNS servers (From before we had DCHP set up) really can REM
it out now....
Filecopy.bat does just that, plus does registry imports....
Favorites.bat copies a folder of important favorites to the users favorites
folder. (I can go the other way to and collect everyones favorites.....It
gets interesting sometimes....)
Fast.bat robocopy's a network folder to a local folder for my parts
department machines to run their parts catalog local.
Flash9 install's flash9....
Java install's java 1.4 (version required for DMS.)
LDAP.bat imports a prf file to set the ldap server for Outlook to use to
resolve email addresses. (I'm not currently using LDAP for anything else.
Kind of waiting on Samba 4....)
AR707 installs Acrobat reader 7.07. (version required for DMS.)
Svg.bat installs Adobe SVG reader. (required by service department program
for looking at wiring diagrams.)
Ffxupdate installs/updates firefox. For Sales Department, but I just let it
install on all.
Printers.vbs installs a certain printer. I really need to figure this out
Stats.bat writes some machine information to a file.
Wsusupdate sets the machine to get it's updates from my WSUS server. (it
recently died, so I had to point them to the new server.)

Some of these were written before I learned some things, so they are not all
Setting and using the variables, for instance.....

You could just use the logon.bat and drives.bat example to get the drives
I need to work on my printers.....

Here's the rest...

(ifmember and robocopy from the W2K3 server resource kit)



net time \\server /set /yes

net use h: \\server\%username% /persistent:yes

\\server\netlogon\ifmember "dominname\client"
if not errorlevel 1 goto accts
net use i: \\server\client

\\server\netlogon\ifmember "dominname\acctsdep"
if not errorlevel 1 goto parts
net use j: \\server\accounts

\\server\netlogon\ifmember "dominname\partsdept"
if not errorlevel 1 goto service
net use k: \\server\parts

\\server\netlogon\ifmember "dominname\servicedept"
if not errorlevel 1 goto sales
net use s: \\server\service

\\server\netlogon\ifmember "dominname\salesdept"
if not errorlevel 1 goto internet
net use l: \\server\sales

\\server\netlogon\ifmember "dominname\internet"
if not errorlevel 1 goto hr
net use s: \\server\internet

\\server\netlogon\ifmember "dominname\hr"
if not errorlevel 1 goto finance
net use m: \\server\hr

\\server\netlogon\ifmember "dominname\finsrvcs"
if not errorlevel 1 goto managers
net use n: \\server\finance

\\server\netlogon\ifmember "dominname\Managers"
if not errorlevel 1 goto public
net use o: \\server\managers

net use p: \\server\public /persistent:yes




if exist "%systemdrive%\Program Files\Microsoft
Office\Office12\excelcnv.exe" GOTO EOF

"%software%\office07compat\fileformatconverters.exe" /passive /quiet




if EXIST "%systemdrive%\program files\microsoft
office\office11\addins\outbak.dll" GOTO EOF

start /wait %software%\pstbackup\pfbackup.exe /q



DNS.bat (was setting it manually using "set dns "Local Area Connection"
xxx.xxx.xxx.xxx" and "add dns "Local Area Connection" xxx.xxx.xxx.xxx
index=2") but now:

@echo ON
REM netsh interface ip set dns "Local Area Connection" dhcp



@ECHO on
xcopy %logondrive%\scripts "%systemroot%\system32\GroupPolicy\user\scripts\"
/s /e /I /v /c /y >NUL
xcopy %logondrive%\scripts\logon\logon.bat %systemdrive%\egn\ /I /y >NUL
xcopy %logondrive%\robocopy.exe %systemroot%\system32\ /Y >NUL
xcopy %logondrive%\hosts %systemroot%\system32\drivers\etc /Y >NUL
xcopy %logondrive%\lmhosts %systemroot%\system32\drivers\etc /Y >NUL
xcopy "p:\templates" "%userprofile%\Application Data\Microsoft\Templates" /I
/c /y >NUL
REM regedit.exe /s %logondrive%\logonmessage.reg
regedit.exe /s %logondrive%\wsus.reg
regedit.exe /s %logondrive%\nosearch.reg
regedit.exe /s %logondrive%\sharedoc.reg
regedit.exe /s %logondrive%\defaultzone.reg
regedit.exe /s %logondrive%\zones.reg
regedit.exe /s %logondrive%\profile.reg


Favorites.bat: (need to change this to use the variables...)

@ECHO on
xcopy "%logondrive%\favorites\*.*" "%userprofile%\favorites\" /y  >NUL


FLASH9.bat: (really old, need to re-look at. Stop using check file to
determine if it needs to run.)

@Echo on

IF EXIST "%systemdrive%\EGN\checks\flash9.chk" GOTO ffx
msiexec /i %software%\Adobe\flash9.msi /q
ECHO %TIME% - %DATE% >> "%systemdrive%\EGN\checks\flash9.chk"
REM ECHO flashinstall - %TIME% - %DATE% >> "%logs%\%computername%.txt"

if EXIST "%systemdrive%\egn\checks\ffxflash9.chk" GOTO EOF
if NOT EXIST "%programfiles%\mozilla firefox\firefox.exe" GOTO EOF
%software%\Adobe\flash9firefox.exe /silent
ECHO %TIME% - %DATE% >> "%systemdrive%\EGN\checks\ffxflash9.chk"
REM ECHO ffxflashinstall - %TIME% - %DATE% >> "%logs%\%computername%.txt"


Ldap.bat: (need to stop using check files....)

@Echo on
if EXIST "%systemdrive%\egn\checks\ldap.chk" GOTO EOF
if NOT EXIST "%systemdrive%\Program Files\Microsoft
Office\OFFICE11\outlook.exe" GOTO EOF
"%systemdrive%\Program Files\Microsoft Office\OFFICE11\outlook.exe"
/importprf "P:\software\ldap\ldap.prf"
ECHO %TIME% - %DATE% >> "%systemdrive%\EGN\checks\ldap.chk"



(this is a bit over my head, as I am really just a hack. I manage to make it
work for this and other software, but all the for/find stuff I really need
to learn better......)

@Echo ON
IF not exist "C:\Program Files\Mozilla Firefox" goto :EOF
Set CV=" (en-US)"
Set "key=HKLM\SOFTWARE\Mozilla\Mozilla Firefox"
For /f "tokens=3* delims=	" %%# In (
	'Reg query "%key%" /v CurrentVersion ^|Find "REG_" 3^>Nul') Do Set
If Not [%rel%]==[%CV%] Start "" /wait
%software%\mozilla\firefox\ffx20014.exe -ms 
del "%allusersprofile%\desktop\Mozilla Firefox.lnk"
Goto :Eof


stats.bat: (need to expand for greater coverage)

ECHO ****************************Logonscript Contents******************* >>
type "c:\egn\logon.bat" >> "%logs%\%computername%.txt"
ECHO ****************************END Logonscript Contents*******************
>> "%logs%\%computername%.txt"
ECHO **************Login User, Date, and Time************************* >>
ECHO Login - %username% - %date% - %time% >> "%logs%\%computername%.txt"
ECHO **************END Login Date and Time************************* >>
ECHO **************IP INFORMATION************************* >>
ipconfig /all >> "%logs%\%computername%.txt"
ECHO **************END IP INFORMATION************************* >>
ECHO **************Get IE Version************************* >>
reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v
Version >> "%logs%\%computername%.txt"
ECHO **************END IE Version************************* >>
ECHO **************Check for Websuite************************* >>
if EXIST "%systemdrive%\Program Files\Adp\ws2000\ws2000.exe" ECHO ADP
installed >> "%logs%\%computername%.txt"
if NOT EXIST "%systemdrive%\Program Files\Adp\ws2000\ws2000.exe" ECHO ADP
NOT installed >> "%logs%\%computername%.txt"
Reg query "HKLM\SOFTWARE\ADP\wsvc" /v Version >> "%logs%\%computername%.txt"
ECHO **************END Check for Websuite************************* >>



' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.AddWindowsPrinterConnection "\\server\Dell3115"


WSUSUPDATE.bat: (used to change wsus servers recently.)

@echo off
Net Stop "wuauserv"
rename "%SystemRoot%\Windowsupdate.log" "Windowsupdate.logold"
Echo Importing WSUS.reg
%windir%\Regedit.exe /s %logondrive%\WSUS.reg
Echo WSUS.reg imported succesfully
Net Start "wuauserv" 
Echo Forcing update detection
wuauclt /detectnow

Wsus.reg: (sets the wsus server)

Windows Registry Editor Version 5.00




What I'd like to know is how to make a certain script run if the machine
name is in a certain file.
Put my parts department machinename in a parts.txt file, and then have the
script check to see if it's there. (or perhaps some other way to accomplish
I just haven't spent the time to look for this yet.

Again, I hope this helps someone, and thanks to everyone on this list.
And of course the Samba developers for Samba in the first place...

More information about the samba mailing list