Mapping drives with login scripts in Active Directory

Farley2k

Senior member
Jan 5, 2003
248
0
71
I am having a tough time finding simple information about what I think is such a simple request.

I want to map several drive letters in login scripts for our users on a windows network (some 2k, and some XP user machines) with Active directory. Simple right? One would think that lots of people would want this. Actictive directory has a great place under the user properties for "profile" where you can put in a home directory but you have to write scripts for more than one mapping apparently. I want users not only to have their home drive mapped but also their departmental shares.

I came from a Netware environment where making these kind of mapping was a breeze! However MS seems to make it a huge deal.

This is the best example I could find on their web site

"// JScript.
var oNet, sUser, cInitial, startTime;
oNet = new ActiveXObject("WScript.Network");
// Get the user name. On Windows 98 and Windows ME, the use may not be logged
// on when the script starts running; keep checking every 1/2 a
// second until they are logged on
sUser = oNet.UserName;
startTime = new Date();
while (sUser == "")
{
var curTime = new Date();
if (curTime ? startTime > 30000) WScript.Quit();
WScript.Sleep(500);
sUser = oNet.UserName;
}
// Add a share for the "h" drive and the printer, based on the
// first letter of the user's name
cInitial = sUser.charAt(0).toUpperCase();
if (cInitial < "L")
{
oNet.MapNetworkDrive("h:", "\\\\server1\\users\\" + sUser);
oNet.AddWindowsPrinterConnection("\\\\printer1\\hp", "HP LaserJet 4");
}
else
{
oNet.MapNetworkDrive("h:", "\\\\server2\\users\\" + sUser);
oNet.AddWindowsPrinterConnection("\\\\printer2\\hp", "HP LaserJet 4");
}
' VBScript.
Option Explicit
Dim oNet, sUser, cInitial, startTime
' Helper object
Set oNet = CreateObject("WScript.Network")
' Get the user name. On Windows 9x, the use may not be logged
' on when the script starts running; keep checking every 1/2 a
' second until they are logged on.
sUser = oNet.UserName
startTime = Now
Do While sUser = ""
If DateDiff("s", startTime, Now) > 30 Then Wscript.Quit
Wscript.Sleep 500
sUser = oNet.UserName
Loop
' Add a share for the "h" drive and the printer, based on the
' first letter of the user's name
cInitial = UCase(Left(sUser, 1))
If (cInitial < "L") Then
oNet.MapNetworkDrive "h:", "\\server1\users\" & sUser
oNet.AddWindowsPrinterConnection "\\printer1\hp", "HP LaserJet 4"
Else
oNet.MapNetworkDrive "h:", "\\server2\users\" & sUser
oNet.AddWindowsPrinterConnection "\\printer2\hp", "HP LaserJet 4"
End If"




Come on! That is a huge pain in the butt plus it about requires a detailed knowledge of JScript! All I want is to map the stupid letter I to a network location!





Anyway does anyone know of a good resource for writing a script to do that? I am not opposed to software that helps me write a JScript if I have to but I the simplest solution is the best as far as I am concerned.


Thanks
 

Saltin

Platinum Member
Jul 21, 2001
2,175
0
0
That script does a little bit more than just map drives for users, but if that's all you want, I'll give you something that will do it in a couple of lines.

net use u: \\fileserv\users\%username% /persistent:yes

Paste that into a new text file and rename it whatever.bat

What it does is maps a network drive U: to the name of the logged in user (%username%) on the server "fileserv" in the "users" folder (which should be shared out).

Actually creating those folders is a little more tricky if they don't exist. If you have a small userbase, just create the folders inside the parent folder "users"yourself, ensuring each child folder matches the users NT username.

Open up Active Directory and then create/modify the group policy object on the OU you want to apply the logon script to.
It's under User Configuration> Windows Settings> Scripts (logon/logoff) in the Group Policy MMC.

Once that is done, any user account inside the OU you linked the GPO to will have the logon script applied. Simple stuff.

 

Farley2k

Senior member
Jan 5, 2003
248
0
71
Thank you.

It can be simple stuff, but lots of places seem to want to make it complicated. I am actually suprised this isn't a wizzard whe creating an object. I believe that most people will want to do a fairly small set of things (map drives, set logon times, etc.) so why not have a simple tool to do that?

Anyway thanks I will test this out on myself and see what happens!

 

Saltin

Platinum Member
Jul 21, 2001
2,175
0
0
believe that most people will want to do a fairly small set of things (map drives, set logon times, etc.) so why not have a simple tool to do that?

Active Directory User's and Computers. You can do pretty much anything from there, in regard to policy, scripting, software publishing and user/computer account management.

If you are coming from an NDS background, you already have a head start learning Active Directory. Good luck!
 

mobogasm

Golden Member
Oct 25, 1999
1,033
0
0
Yeah login scripts are pretty simple specially if you're coming from a novell background. Should be pretty similar in nature for the most part.
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
An example basic .bat file for mapping drives in a Win2k/9x mixed environment:

@echo off
echo Greetings, %username%

echo Synching time with Eyesee8...
NET TIME /SET \\server /yes

if not "%OS%"=="Windows_NT" goto :WIN9X

if exist H:\*.* NET USE H: /delete
echo Mapping H:\...
NET USE H: \\server\Data1 /persistent:no /yes
if exist M:\*.* NET USE M: /delete
echo Mapping M:\...
NET USE M: \\server\Data1\users\%username% /persistent:no /yes
if exist I:\*.* NET USE I: /delete
echo Mapping I:\...
NET USE I: \\server\Data2 /persistent:no /yes
if exist N:\*.* NET USE N: /delete
echo Mapping N:\...
NET USE N: \\server\Data1\website /persistent:no /yes
goto SCRIPT

:WIN9X
if exist %windir%putinenv.exe goto :NOCOPY
copy \\server\netlogon\putinenv.exe %windir%\*.*
:NOCOPY
%windir%\putinenv.exe L /L
\\servernetlogon\winset USERNAME=%username%

if exist H:\*.* NET USE H: /delete
echo Mapping H:\...
NET USE H: \\server\Data1$
if exist M:\*.* NET USE M: /delete
echo Mapping M:\...
NET USE M: \\server\%username%$
if exist I:\*.* NET USE I: /delete
echo Mapping I:\...
NET USE I: \\server\Data2
if exist N:\*.* NET USE N: /delete
echo Mapping N:\...
NET USE N: \\server\website$
 

dbwillis

Banned
Mar 19, 2001
2,307
0
0
I use a VB Script for my drives in AD.

2K and XP clients.


Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "K:", "\\ERDHFDNAS002\ECCC_Info"

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "N:", "\\PL-PLIC-SRV1\OLForms"

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "V:", "\\PL-PLIC-SRV1\Folio"
 

Farley2k

Senior member
Jan 5, 2003
248
0
71
Ok, next question.

Where do you put the file? On the domain controller I put the .bat file in the winnt\sysvol\ directory and I also tried the winnt\sysvol\sysvol directory. In neither case did the script acutally run.

I need to play around more I am sure but I wondered where it need to be.

Thanks
 

mikecel79

Platinum Member
Jan 15, 2002
2,858
1
81
You can put the batch files in your netlogon shares on your Domain Controller. Are you assigning the scripts through a policy? Or are you putting it in the logon script field under ADUC? If in the logon script field then you need to put them in the netlogon shares on your DCs.
 

Farley2k

Senior member
Jan 5, 2003
248
0
71
I am thinking I want to make them part of a policy. It would be eaiser I think to manage different logins for departments if they were policies in the OU for the department.

 

dbwillis

Banned
Mar 19, 2001
2,307
0
0
I put my .VBS files in the Netlogon shared folder on the Domain Controller and specify them in Group Policy