Script to automatically map samba shares as network drive


 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Script to automatically map samba shares as network drive
# 1  
Old 01-31-2011
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.
# 2  
Old 02-10-2011
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:

Code:
'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:
Code:
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
# 3  
Old 02-10-2011
barrydocks,

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

netlogon.bat File Contents
Code:
 
@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
Code:
 
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.
# 4  
Old 02-11-2011
Thank stringman, this works a treat!Smilie

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
# 5  
Old 02-11-2011
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with accessing Samba shares on external (NON-DOMAIN) webserver(s)

Hi all, You may have seen my recent topic, where I asked for help getting some samba shares to work on our network. Now that these are working, I move on to the next hurdle! We have a few externally hosted (Windows Server 2008 R2) web servers which are not on our domain, but can still... (0 Replies)
Discussion started by: mgreen81
0 Replies

2. UNIX for Dummies Questions & Answers

Map network drive

Hi I need to restore an oracle backup from production in a test x86 Solaris 10 box . But the space is limited and does not have enough to hold both the backup as well as database . Hence , I am thinking of mapping a network drive from another x86 Solaris 10. Pls let me know if it is... (3 Replies)
Discussion started by: Rossdba
3 Replies

3. UNIX and Linux Applications

Copy numerous private Samba-shares as one user. (Syntax question)

Hello Forum, I was overwhelmed by how fast and correct the responses to my first question in this forum was, and I hope I expreience this again today. The reason is that I have to copy a fileserver (Ubuntu 8.04 32 with Samba) to another server via Internet within tomorrow. I have no problem... (0 Replies)
Discussion started by: primaxx
0 Replies

4. UNIX for Dummies Questions & Answers

Help mounting Samba shares

I have these two shares on my Ubuntu Server: path = /media/share read only = no guest ok = yes path = /var/www read only = noI want to mount them to the directories that I created on my Desktop called "shared" and "www" how do I do this? I ran the command: smbclient -L... (1 Reply)
Discussion started by: shadowcat
1 Replies

5. UNIX for Dummies Questions & Answers

Samba - Creating shares

So I have Samba installed on my server and I have to create two shares. Make a backup of your smb.conf - call it smb.conf.orig. Create a share called shared that allows read and write permissions for everyone and points to /media/shared. Create another share called www that points to the... (1 Reply)
Discussion started by: shadowcat
1 Replies

6. Linux

Auto map network drive using SAMBA with batch file

Hi everyone. I have several shares (see smb.conf below). Each setup fairly similarly, and several groups. My end goals are: 1) to have the share automatically map as the P: drive to members of the employees group 2) to have the share automatically map as the t: drive to members of the tech... (0 Replies)
Discussion started by: unassassinable
0 Replies

7. Shell Programming and Scripting

extraction of samba shares with sed

Hi there, My samba configuration file looks like that : ... ... path = /home/samba/profiles/ ... path = /home/samba/shares/family valid users = family path = /home/samba/shares/admins valid users = admins path = /home/samba/shares/publicI want to extract the list of standard... (3 Replies)
Discussion started by: chebarbudo
3 Replies

8. UNIX for Dummies Questions & Answers

Map Drive From Windows To Apache Shared Drive?

Anyone know how I can map a windows drive to an apache shared drive? In my httpd.conf file, I have: Alias /merc_rpts/ "/u/merc_rpts/" <Directory "/u/merc_rpts"> Options Indexes </Directory> I'm able to bring up a browser and see the contents of this folder. In... (0 Replies)
Discussion started by: gseyforth
0 Replies

9. IP Networking

How to enumerate samba shares with client

I have a samba server node and I want to mount the samba (CIFS) shares from a second (client) unix machine. However, the unix mount command requires I specify the name of the share. What if I don't know the name of the share? How can I enumerate all the shares from the samba client machine? ... (1 Reply)
Discussion started by: siegfried
1 Replies

10. Solaris

Map Network Drive...

Hallo...Hi, Anyone can help me???How can I map network drive from Windows if i'm using the Sun Solaris 8 server? :confused: (1 Reply)
Discussion started by: mrboomber
1 Replies
Login or Register to Ask a Question