Following on from this excellent post on mapping samba shares as networked drives for XP clients:
http://forum.zentyal.org/index.php?topic=2019.0I have tried to collate some information to make this more useful and also redirect "My Documents" to the users /home folder.
Ok to make this work properly you need to have the appropriate logon.bat, logon.vbs file, a separate vbs file to map my documents called map_mydocs.vbs and a file to make the changes to samba configuration.
1. create a logon.bat file:
nano /home/samba/netlogon/logon.bat
paste the following:
@echo off
REM removes any network drives in use by user
@if exist h: net use h: /delete /yes
@if exist g: net use g: /delete /yes
#@if exist p: net use p: /delete /yes #repeat this for any other mapped drives
REM Maps shares as network drives
cscript \\yourservername\netlogon\logon.vbs
REM Syncronize the time on the workstation to that of the server.
net time \\yourservername /set /yes
REM Map "My Documents" to the user's G: Drive
if EXIST "G:\" (
cscript "\\yourservername\netlogon\map_mydocs.vbs"
)
2. create the logon.vbs as per the original post:
nano /home/samba/netlogon/logon.vbs
paste the following:
'First make sure all variables are dimensioned.
'This isn't necessary for functionality; it's for coding discipline only.
Option Explicit
'dimension all our variables
dim objNetwork
dim strDriveLetter, strRemotePath, strUser, strGrp
dim strGroupADSPath, strUserADSPath, grp
'This script will use the MapNetworkDrive method
'for each network drive mapped.
'We'll be using the Wscript.Network Object to enumerate the user as well as to map drives.
'We only need to instantiate it once at the beginning.
Set objNetwork = Wscript.CreateObject("Wscript.Network")
'First let's get the user name since we'll use it for mapping the home directory
'as well as checking group memberships.
strUser = objNetwork.UserName
'In just about every network at least two drives are mapped:
'One for the user's home directory, and one for an organizational public share.
'We'll map those first since they don't depend on group memberships.
'User Drive to G:
strDriveLetter = "G:"
strRemotePath = "\\yourservername"
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath & "\" & strUser
'PublicShare Drive to P:
strDriveLetter = "P:"
strRemotePath = "\\yourservername\public"
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
'next we'll enumerate groups and map drives for specific departmental memberships
'The code to check for memberships and map the drives is in a subroutine called IsMember.
'All we have to do is copy the same block over again for each group membership we want to check.
'The block only needs to set the string values for the group name, the desired drive letter, and the share path.
'Then it calls the IsMember subroutine down below.
'Q: for members of groupq
strGrp="groupq"
strDriveLetter = "q:"
strRemotePath = "\\yourservername\groupqpvt"
IsMember
'R: for members of groupr
strGrp="groupr"
strDriveLetter = "R:"
strRemotePath = "\\yourservername\grouprpvt"
IsMember
'Repeat for as many private groups and their respective enumerated shares as you wish.
'We're done with the login script.
'Let's tidy up variables first to make sure we're not leaving anything behind.
objNetwork = ""
strDriveLetter = ""
strRemotePath = ""
strUser = ""
strGrp = ""
strGroupADSPath = ""
strUserADSPath = ""
grp = ""
'That's all. Close the script processor.
wscript.quit
sub IsMember
'set the directory service path to enumerate the group
strGroupADSPath = "WinNT://yourdomain/" & strGrp & ",group"
'poll the PDC for the group
set grp = GetObject(strGroupADSPath)
'set the user directory service path to enumerate the user
strUserADSPath = "WinNT://yourdomain/" & strUser
'Check membership in the group.
If (grp.IsMember(strUserADSPath)) Then
'map the drive
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
End If
'clean up variables for next group check.
strGrp = ""
strDriveLetter = ""
strRemotePath = ""
'Rinse, lather and repeat this code as many times as needed.
End sub
3. Then create the script map_mydocs.vbs:
nano /home/samba/netlogon/map_mydocs.vbs
paste the following:
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal", "G:\"
You will also need to remove the line from smb.conf that maps the /home folder to H:
nano /etc/ebox/hooks/samba.postsetconf
paste the following:
#!/bin/sh
sed -i '/logon drive =/ d' /etc/samba/smb.conf
exit 0
Make the file executable:
chmod +x /etc/ebox/hooks/samba.postsetconf
The samba.postsetconf script is called just as before samba is started and will make the appropriate alterations to the smb.conf which would otherwise be overwritten by zentyal
Please post any glaring errors or typos or any useful amendments
Thanks to the guys who post on the original thread