Script to automatically map samba shares as network drive

Hopefully someone will be kind enough to help me. I have a fileserver acting as a PDC and providing samba shares to a small network. Authentication to the PDC is via LDAP (setup using ebox) The users all have real local accounts on the server.

I would like a windows logon script that will:

  1. automatically mount the samba shares as mapped networked drives, ie:
    /media/share1 to P:
    /media/share2 to Q:
  2. map the "My Documents" folder to the users /home share which I think is automatically mounted as H:

Ideally I would like to map the shares that are specifically available to different groups but this is not essential, ie share1 to group A and share 2 to group A & B.

Thanks in advance.

Ok I have made some headway on this will a little help from another forum. I have the following script to mount samba shares as mapped drives according to user group which works well:

'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 U:
'strDriveLetter = "U:"
'strRemotePath = "\\yourservername"
'objNetwork.MapNetworkDrive strDriveLetter, strRemotePath & "\" & strUser

'PublicShare Drive to P:
strDriveLetter = "P:"
strRemotePath = "\\server10\Staff"
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.

'V: for members of admin   
strGrp="admin"
strDriveLetter = "V:"
strRemotePath = "\\server10\Sage"
IsMember

'W: for members of hoyalog
strGrp="hoyalog"
strDriveLetter = "W:"
strRemotePath = "\\server10\Hoyalog"
IsMember


'X: for members of focus
strGrp="focus"
strDriveLetter = "X:"
strRemotePath = "\\server10\FocusData"
IsMember

'Y: for members of clinical
strGrp="clinical"
strDriveLetter = "Y:"
strRemotePath = "\\server10\ClinicalImages"
IsMember

'Z: for members of focus
strGrp="focus"
strDriveLetter = "Z:"
strRemotePath = "\\server10\PracticeDocuments"
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://JONESANDJONES/" & strGrp & ",group"
'poll the PDC for the group
set grp = GetObject(strGroupADSPath)
'set the user directory service path to enumerate the user
strUserADSPath = "WinNT://JONESANDJONES/" & 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

I have also looked at this script for redirecting My Documants to the users /home folder on the samba server:

Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User
Shell Folders\Personal", "H:\"
'WSHShell.RegWrite
'"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User
'Shell Folders\My Pictures", "H:\My Pictures"

I have tried creating a bat script that calls these vbs scripts sequentially by the second does not seem to run.

Any suggestions?

Is it possible to combine these in the same script?

Thanks

barrydocks,

I can show you we use. I didn't write it, but it looks very similar to your requirements.

netlogon.bat File Contents

 
@ECHO OFF
REM Check for "X" drive and map if not available
if NOT EXIST "X:\" (
net use X: \\trantor\raid0 /PERSISTENT:YES
)
REM Check for "H" drive and map if not available
if NOT EXIST "H:\" (
net use H: /home
)
REM Syncronize the time on the workstation to that of the server.
net time \\trantor /set /yes
REM Map "My Documents" to the user's H: Drive
if EXIST "H:\" (
cscript "\\trantor\netlogon\scripts\map_mydocs.vbs"
)
 

map_mydocs.vbs File Contents

 
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal", "H:\"

These scipts will map our "X" drive, which is our shared RAID and also an H drive for each users "My Documents". User profiles are located on our RAID.

Hope this helps.

Thank stringman, this works a treat!:slight_smile:

I also like the idea of syncing the client time with the server, any idea how to add to the script to disable the user from adjusting the time?

Thanks

barrydocks,

The only way I know is to go to Local Security policy --> User Rights Assignment and set "Change System Time" to Administrators only. I have to leave now tp ick up my daughter, but I'm sure the registery setting for this can be found online.

Ken