1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Roaming user login script needs to map drives...

Discussion in 'Windows Server' started by axis77, Apr 21, 2010.

Thread Status:
Not open for further replies.
  1. axis77

    axis77 Thread Starter

    Joined:
    Aug 31, 2004
    Messages:
    650
    I have a user that moves from different locations every week, so for example he can be at area A with ServerA, then area B with ServerB
    What im looking for is a way to run his login script that would know if he was at area A or Area B and mapped that specific servers folder share...
    ex. current script
    map network drive n: \\serverA\share

    but if he was in Area B today his script still says
    map network drive n: \\ServerA\share

    How do I make a roaming script that knows if hes at AreaA or AreaB???
    map network drive n: \\%Servername%\share

    Any Ideas?
     
  2. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Assuming each location has been configured into a different Active Directory site, use gpresult (gpresult /R for Vista/Win 7) or a VBScript to get the Site name, then use that to read the appropriate server name from a list of sites
    Code:
    For /F "Tokens=3 Delims=: " %%I In ('gpresult ^|Findstr /I /C:"Site Name:"') Do Set _SiteName=%%I 
    For /F "Tokens=2 Delims=:" %%I In ('Type Serverlist.txt^|Findstr /I "%_SiteName%"' ) Do Set _Servername=%%I
    Serverlist.txt should be in the same folder as the logon script, or the path should be specified, andbe setup like this, using the correct site and server names:

    Site1:ServerA
    Site2:ServerB
    Site3:ServerC

    Example:
    Building05:WarehouseServerA

    This VBScript should be faster than waiting for the entire gpresult output to be generated.
    Save the following as FindSite.vbs:
    Code:
    Set objADSysInfo = CreateObject("ADSystemInfo")
    WScript.Echo "Site Name: " & objADSysInfo.SiteName
    Then use this to get the site name
    Code:
    For /F "Tokens=3 Delims=: " %%I In ('cscript //nologo FindSite.vbs') Do Set _SiteName=%%I
    For /F "Tokens=2 Delims=:" %%I In ('Type Serverlist.txt^|Findstr /I /C:"%_SiteName%"' ) Do Set _Servername=%%I
    
    If you haven't set up sites, you'll need to find something you can read that is unique to each location, such as an IP address (Default Gateway, DNS, DHCP, WINS).
    If the sites are not connected, you can use the logonserver variable, however, if a logon server isn't available, and the system logs on using cached credentials, the logonserver variable will contain the name of the last server that processed the credentials, which could be for a different site.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/918213

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice