wsh script to map drives referencing domain controller.

Posted on 2004-10-24
Last Modified: 2008-02-01
I have a network which is run on a single domain using MS Enterprise Server 2003. The domain controls 13 separate sites which each have their own domain controllers.

My boss wants me to implement a wsh script which will allow users to log on to and use only the mapped drives specified for their particular domain controller.

In other words, the drives for each user would be mapped on the domain controller machines as opposed to mapping them on the primary domain controller

I am a novice script writer..

I need help with the script and instructions on installing it.

Please help!


Question by:DrD
    LVL 11

    Accepted Solution

    You should do that with Group Policies.
    i am not sure if you want them to log on to the DC's. Its a security issue to not allow this.
    but if yes, you have to modify the "Default Domain Controller Policy"
    If they log on to normal clients, the "Default Domain Policy" counts.
    browse through it and look if it can do, what you want to do :)

    Author Comment

    The question more specifically is this:

    I have to write a scipt using WSH which I would implement using group
    The script would map drives to user computers as they log on.
    However, since we have one domain but a number of domain controllers (a
    domain controller in each site), I need a way to map drives according to the
    D.C the user is using to authenicate him/herself.
    For example if a user is in Site A,using Domain controller A then the mapped
    drive he/she would receive would be X:\ mapped to share A
    If a user is in Site B, using Domain controller B then the mapped drive
    he/she would receive X:\ mapped to share B.

    The WshNetwork object allows you to map drives according to three
    properties: UserName, Computer Name and UserDomain

    For example to map a network drive according to User Domain would be

    Set objNetwork = Wscript.CreateObject ("Wscipt.Network")
    strUserDomain = objNetwork.UserDomain

    If strUserDomain = "ACCOUNTING" Then
       objNetwork.MapNetworkDrive "X:", "\\fileserver01\accounting", True
    Else if strUserDomain = "DEVELOPMENT" Then
       objNetwork.MapNewtorkDrive :X:",  "\\fileserver01\accounting", True
    End If

    However the WshNetwork object doesn't have a property to map drives
    according to the Domain Controller one is trying to authenicate oneself

    Does anyone have a way around this?
    LVL 4

    Assisted Solution

    I know a sure fire way in Dos shell scripting

    You could use this.

    NET USE X: %logonserver%\accounting

    This will always map the drive to the share that is attached to the server you logged on from.  Now in some cases your users may log onto a server that is not local.  If this happens then access to that drive will be slow. Hope that helps.  If you have to use a WSH script you could always launch the dos script first then call the wsh script using the logon server as a switch

    Start %logonserver%\netlogon\wshscript.vbs %logonserver%

    Good luck

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
    On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now