Script to map home drive for users

Currenly I mapping a users "h" home drive with an entry in the users properties under the home folder path. I would like to script so that when users log in they are mapped to their h drive on a server.

Each user has a shared with with the correct permissions on the server. The share is username$
So in the home folder properties its \\server\username$

Thanks in advance
Who is Participating?
chandru_solConnect With a Mentor Commented:
Try this..........

Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strUserName = objUser.samAccountName
strDrive = "\\domain\share\share\" & strUserName & "$"
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.MapNetworkDrive "H:", strDrive

Open in new window

vmamedovAuthor Commented:
I would also like to use DFS, so the location of the home drive would be \\domain\share\share\username$

As i understand correctly, you do NOT wish to use the AD integrated homefolder option en want to script it ?

How about this in the loginscript:

Net use H: \\domain\share\share\%username%$

Where you use the environment variable %username%

If I do not understand correctly please say so :p

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

vmamedovAuthor Commented:
I have tried that and it doesnt work, it doesnt map the drive,
also i am looking for a vb script not batch
arg C beat me again. /sigh
vmamedovAuthor Commented:
chandru, thanks for your help
after running the script i am getting the following error

Windows Script Host
Script:      C:\Documents and Settings\user\Desktop\hdrives.vbs
Line:      11
Char:      1
Error:      The system cannot find the file specified.

Code:      80070002
Source:       WSHNetwork.MapNetworkDrive

vmamedovAuthor Commented:
i figured out what i was doing, there was a problem with DFS

thanks both
How did you fix the issue? I am getting same error when I run the script.
vmamedovAuthor Commented:
adrian whats is the problem that you are having?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.