Reply
Old August 8th, 2007 Top | #1
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default SBS 2003 assigning mapped drives?

Hey All,

Was wondering if I can setup SBS2003 to assign mapped drives to workstations instead of me going around manually mapping them from each workstation?


Thanks,

Heeter
Heeter is offline   Reply With Quote
Old August 8th, 2007 Top | #2

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

use a login script, assign the login script to the user accounts
fitz is offline   Reply With Quote
Old August 8th, 2007 Top | #3
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Thanks Fitz,

would you know of a copy that I can find of this logon script that I could use as a template?

Since it is a script, I am presuming that it is a .bat file, am I correct?


Thanks,

Heeter
Heeter is offline   Reply With Quote
Old August 8th, 2007 Top | #4

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

you can use either batch or VBScript/WSH (windows Script Host) - technically, you can also use KIX and some other ones too..

in Batch:
net use <drive letter> <share path>
Code:
net use z: \\server1\shareMe
in VBScript
Code:
set objNet = CreateObject("wscript.Network")
objNet.MapNetworkDrive "z:","\\server1\shareMe"
Note: neither of these does much error checking.. for example, if the drive letter is already mapped, it will fail. You can put in some error checking etc and remap drives if needed.

Since I prefer VBScript, you can copy my script below and hack it up for your needs. It does some minor error checking..
Code:
set objNet = CreateObject("Wscript.Network")
set objFSO = CreateObject("Scripting.FileSystemObject")

strPath = "\\server1\shareName"
strDriveLetter = "z:"

'checks to see if the drive letter is already mapped
if not ( objFSO.DriveExists(strDriveLetter) ) then 

    'drive is not mapped, so just map the drive and we're done
    objNet.MapNetworkDrive strDriveLetter,strPath

else    

    'if the drive is already mapped, check to see if it is mapped to the correct share
    'if the drive is mapped correctly, nothing to do
    'if the drive is mapped to a different share, disconnect the share and map correctly
    set objDrive = objFSO.GetDrive(strDriveLetter)
    if not (objDrive.ShareName = strPath) then
        objNet.RemoveNetworkDrive strDriveLetter,true,true
        objNet.MapNetworkDrive strDriveLetter,strPath
    end if
end if
The scripts will go into the netlogon share of the domain controller (in this case your SBS server). Going into ADUC (Active Directory Users and Computers) you can assign the script under the profile tab in the user account properties. Technically, you can also use a GPO to assign a login script.


edit: and madmatt.. piss off and stop bugging me in IM to post a script
fitz is offline   Reply With Quote
Old August 8th, 2007 Top | #5
 
madmatt's Avatar
Bow Down to the King
Joined: April 2002
Location: New York
Posts: 13,312
Reputation: 4090
Power: 294

Default Re: SBS 2003 assigning mapped drives?

Just making sure you fulfill your duties as a moderator and master scripter. =)

madmatt is offline   Reply With Quote
Old August 9th, 2007 Top | #6
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Awesome, thanks for the template!!!!!!


Should I go around and disconnect the existing mapped drives?

With this setup, I will presume that I can create a different vbscript for each drive that I would like to map, would this be correct?

saving this file would be *.vbs, like in my situation it would be datadrive.vbs and specdrive.vbs, etc, etc?


Thanks again for all your help.



Heeter
Heeter is offline   Reply With Quote
Old August 9th, 2007 Top | #7
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Originally Posted by madmatt View Post
Just making sure you fulfill your duties as a moderator and master scripter. =)

Thanks for lighting a fire under his butt, Matt, LOLOL



Heeter
Heeter is offline   Reply With Quote
Old August 9th, 2007 Top | #8

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

Originally Posted by Heeter View Post
Awesome, thanks for the template!!!!!!

Should I go around and disconnect the existing mapped drives?
well, I like to do it to make sure my users are all connected to the correct drives as some of them got into the habit of remapping drives. The script snippet I wrote will automagically disconnect the drive if the drive letter that you are trying to map correctly is in use.

With this setup, I will presume that I can create a different vbscript for each drive that I would like to map, would this be correct?

saving this file would be *.vbs, like in my situation it would be datadrive.vbs and specdrive.vbs, etc, etc?
funny.. madmatt asked me the same question in an IM..

basically, no - you don't create seperate scripts for each drive. The user account properties will only accept a single login script file (although, technically I suppose you could create seperate vbs files and call them through a bat file and have the bat file as your one login script.

But, generally, you'll wrap it into one file. You could remove the variables (strDriveLetter and strPath) and use the actual string values and write multiple connect lines like:
Code:
objNetwork.MapNetworkDrive "y:","\\server\share1"
objNetwork.MapNetworkDrive "z:","\\server\share2"
.
.
.
But you would have to wrap the lines to check each drive letter and disconnect the existing drive for each path if you wanted that functionality.

A better way would be to turn the mapping script section into a function/subroutine and call the function from the main script. Something along the lines of this:

Code:
MapDrive "x:","\\192.168.25.103\c$"
MapDrive "y:","\\192.168.25.103\e$"
wscript.quit

Function MapDrive(strDriveLetter,strPath)
  set objNet = CreateObject("Wscript.Network")
  set objFSO = CreateObject("Scripting.FileSystemObject")

  if not ( objFSO.DriveExists(strDriveLetter) ) then 
     objNet.MapNetworkDrive strDriveLetter,strPath
  else    
     set objDrive = objFSO.GetDrive(strDriveLetter)
     if not (objDrive.ShareName = strPath) then
        objNet.RemoveNetworkDrive strDriveLetter,true,true
        objNet.MapNetworkDrive strDriveLetter,strPath
     end if
  end if
End Function

Originally Posted by Heeter View Post
Thanks for lighting a fire under his butt, Matt, LOLOL
yeah.. I think he called me lazy or something along those lines asking why I didn't just post the script. I havea copy of the IM conversation somewhere on my work laptop (working on my home machine now).
fitz is offline   Reply With Quote
Old August 9th, 2007 Top | #9
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Thanks again, for your input and time.

I am going to be making the mods to the SBS2003 Domain Controller in the morning, and I am certainly going to use that last one you posted. Everyone is going to see the same two drives:

So it should look like this:

Code:
MapDrive "M:","\\server\D:\Data$"
MapDrive "N:","\\server\D:\Spec$"
wscript.quit

Function MapDrive(strDriveLetter,strPath)
  set objNet = CreateObject("Wscript.Network")
  set objFSO = CreateObject("Scripting.FileSystemObject")

  if not ( objFSO.DriveExists(strDriveLetter) ) then 
     objNet.MapNetworkDrive strDriveLetter,strPath
  else    
     set objDrive = objFSO.GetDrive(strDriveLetter)
     if not (objDrive.ShareName = strPath) then
        objNet.RemoveNetworkDrive strDriveLetter,true,true
        objNet.MapNetworkDrive strDriveLetter,strPath
     end if
  end if

End Function
I am going to save it as "mapped.vbs"

I won't bother with going around and disconnecting the M: mapped drives already there.

How does this look to you?


I can't thank you enough for your time....



Heeter
Heeter is offline   Reply With Quote
Old August 9th, 2007 Top | #10

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

Originally Posted by Heeter View Post
Thanks again, for your input and time.
no worries
I am going to be making the mods to the SBS2003 Domain Controller in the morning, and I am certainly going to use that last one you posted.
Make sure you remember to add the script to the user account so they actually run the script when they login.
[code]
MapDrive "M:","\\server\D:\Data$"
MapDrive "N:","\\server\D:\Spec$"
wscript.quit
I'm not sure if \\server\d:\data$ is a valid share name.. you may want to test that before hand and make sure you are using the correct share path.

I won't bother with going around and disconnecting the M: mapped drives already there.
As I mentioned, the script code I wrote will check and disconnect an M: drive already if it is not mapped to the correct share. The script it self will do it so you don't have to do it yourself physically.
fitz is offline   Reply With Quote
Old August 15th, 2007 Top | #11
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Update,

Thanks Fitz,

I still haven't quite figured out the filepath for the shared drives on the network, but it is something that I will continue to play with as I go along. Right now, it is disconnecting the manually mapped drive when the user logs on, but not issuing the vbs mapped drives.

I erased the default .bat file that was in the logon script section of the profile. But I was wondering if I could of just added the vbs script to the original line, sort of like this into the logon script line of the profile:

Code:
logonscript.bat; mappeddrive.vbs
I don't know if this works or not, can't really see the difference.


Heeter
Heeter is offline   Reply With Quote
Old August 15th, 2007 Top | #12

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 302

Default Re: SBS 2003 assigning mapped drives?

This is pretty darn cool - when I first read this thread I remember thinking " why do you need error checking for a login script?" But, this actually will override anything they have done locally? Such as....

login script says

net use m: \\contoso1\mattspr0n

Physical Drive mapping (done manually says)

m drive is mapped to \\contoso1\mattschildhoodphotos

So regardless, Matt's pr0n will always be mapped to M?

How would you go about addressing login scripts that don't seem to run when the person is working from home? Obviously they don't hit the PDC when logging into their machines using cached credentials, and after connecting to the VPN can only access drives that were mapped from a previous session.

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old August 16th, 2007 Top | #13

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

Originally Posted by kcnychief View Post
So regardless, Matt's pr0n will always be mapped to M?

How would you go about addressing login scripts that don't seem to run when the person is working from home? Obviously they don't hit the PDC when logging into their machines using cached credentials, and after connecting to the VPN can only access drives that were mapped from a previous session.
yup.. the M: drive would also map correctly.

as for VPN, it may depend on what VPN Client is being used.. most clients have some option to run a script after login (in which case, see if it will handle vbs scripts or just wrap the vbs script in a batch file).

The bigger question on VPN logins is how to get any login script to run at all if they already logged in via Cached credentials.. connecting via VPN using the "login using dial-up" checkbox on the main GINA is a different story..

If your VPN client supports it, it may be possible to run a post-login/post connection script off the VPN client which might require the script be local on the machine.. and if it won't support vbs would require a BAT file wrapper.. the harder part on that is making sure the local script is updated when changes to the main script changes.

edit:
you could also write a local process/service that installs on the client to either watch for VPN connections and/or monitors IP changes and runs the login script that way.

It's the same issues as when a laptop user can start a computer off the network and later plug in and/or dock the laptop - no login scripts. Or if a computer's network cable is unplugged at startup and after logging in with cached credentials, they plug in the network cable..
fitz is offline   Reply With Quote
Old August 25th, 2007 Top | #14
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Update:
I am still having issues with my mapped drive vbscript. It is disconnecting the existing M drive, but it is giving me errors, please see screenie.

Folder to map is on E:: drive (E:/ClientData), would like to call it M: drive

Thanks,

Heeter
Attached Thumbnails
SBS 2003 assigning mapped drives?-mapped.jpg  
Heeter is offline   Reply With Quote
Old August 26th, 2007 Top | #15

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 302

Default Re: SBS 2003 assigning mapped drives?

I'm assuming if it can't find the path from the computer that is trying to run it, the user who is running the script might not have access to that admministrative share?

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old August 26th, 2007 Top | #16
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

All the users that I have applied this script to in their profile have this error come up.

The folder in question has full admin/everyone privileges assigned to it.

I do manually map the drive from the workstation when I am logged in as the user. but when I relogon, the mapped M: drive gets disconnected (As the script intends it to do) and I get this error.


Heeter
Heeter is offline   Reply With Quote
Old September 5th, 2007 Top | #17

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

not sure what the problem is. The error indicates that it doesn't think the share exists..

You said the m: drive gets disconnected, it should only get disconnected if the m: drive is connected to a different share (for example: the m: drive is already mapped correctly to \\1600SC\NonClientData, the script would disconnect it).
If you have the M: drive connected correctly and the script is disconnecting the drive, then you are passing the wrong share string into the script.

just for kicks, go to your start/run and just type in "\\1600SC\clientData$" (without the quotes).
fitz is offline   Reply With Quote
Old September 5th, 2007 Top | #18
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Start/run, It works without the share sign

\\1600sc\clientdata$ <-doesn't work
\\1600sc\clientdata <-works


Thanks Fitz, for your help so far.........



Heeter
Heeter is offline   Reply With Quote
Old September 5th, 2007 Top | #19

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164

Default Re: SBS 2003 assigning mapped drives?

the $ is the mark to set a share as a hidden share.. if you didn't create it as a hidden share, you don't use the $ symbol.

The share path that gets passed should be the same as what you would use in the start/run (or when you map the drive any other way), so your first line of the script you are using should read:

Code:
MapDrive "M:","\\1600SC\ClientData"
fitz is offline   Reply With Quote
Old September 5th, 2007 Top | #20
 
Heeter's Avatar
Overclocked Like A Mother
Joined: July 2002
Location: In front of my computer
Posts: 2,729
Reputation: 684
Power: 150

Default Re: SBS 2003 assigning mapped drives?

Oh, Okay

Hidden Share, got it.

Thanks for enlightening me on this one,

Will fix up the script.

If there is two scripts that I would like to use on a user's profile, do I seperate the scripts with a ";" or just a space between them?

Thanks a million for your help, I really appreciate it.

Heeter
Heeter is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
Office and Mapped Network Drives omg its nlm Windows Desktop Systems 5 January 29th, 2007 10:18pm
win 98 behind a router loosing mapped drives on XP mfenech Windows Desktop Systems 0 October 24th, 2006 8:26pm
Automatically re-connect mapped drives? saeltmarae2k Windows Desktop Systems 5 August 29th, 2006 1:11am
what causes mapped drives to be disconnected usghvn2002 Windows Server Systems 12 March 24th, 2006 10:12pm
Keep entering password for mapped drives Heeter Windows Server Systems 15 January 24th, 2006 11:25pm