Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Login script / map home folder.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Login script / map home folder.


    I have a 2003 AD with 600 XP workstations. 4 DC's.

    I run a loginscript that maps two networkdrives and the home folder. 3 mappings in total.

    The problem is that almost every day a few users report that they don't get their home-folder mapped correctly.

    The mapping should be like this: \\servername\home$\username
    When it fails, the mapping looks like this: \\servername\home$\

    So the user gets the entire "Home$" share mapped, and ofcourse cannot access this folder, resulting in a "access denied" error. If the user logs of and on again... everything is fine...

    I don't see anything strange in the eventlogs on the client-computer, and on the DC the user gets a successful security audit...

    The loginscript is run by GPO and looks like this:


    Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path

    Set WSHShell = CreateObject("WScript.Shell")
    Set WSHNetwork = CreateObject("WScript.Network")

    Set objDomain = getObject("LDAP://rootDse")
    DomainString = objDomain.Get("dnsHostName")

    WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

    UserString = WSHNetwork.UserName

    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

    strComputer = WSHNetwork.ComputerName

    'Set clDrives = WshNetwork.EnumNetworkDrives
    'For i = 0 to clDrives.Count -1 Step 2
    'WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True

    wscript.sleep 600

    WSHNetwork.MapNetworkDrive "O:", "\\server1\Operations",True
    WSHNetwork.MapNetworkDrive "P:", "\\server1\Production",True
    WSHNetwork.MapNetworkDrive "U:", "\\server2\home$\" & UserString,True


    On the user properties in AD users and computers I also map the U: to the users home-path...: Connect U: To: \\server2\Home$\username

    I have tried to remove the mapping of U: from the login-script to get it to just use the path I have set in AD users and Computers, but then the users dont get a U: mapped at all... is this correct behavior when running a loginscript?

    Ideas / pointers?
    Greetings from
    Petter C.

  • #2
    Re: Login script / map home folder.

    I would suggest you use either a logon script or else specify on the users properties. The way you are doing it now, you are basically trying to do the same thing twice (if am correct) and it may be a conflict in there somewhere. Saying that, the error you get points more towards a permissions issue. What are your share and ntfs permissions on the Home folder?

    Caesar's cipher - 3




    • #3
      Re: Login script / map home folder.

      I agree, either one or the other sounds like the best solution... but if I remove the home-mapping from the loginscript (tried this morning) alot of users reported that they got no U: at all... even though the mapping is set on the users properties. (This also bugs me...)

      The permissions on the Home folder is:

      Authenticated users: change/read
      (Should I change this to: everyone: full control?)

      administrators: full
      Creator Owner: special
      System: full

      On any given users folder the permissions is as above plus the user itself has full control.

      I agree that it sounds like a permissions issue, however... if that was the case... wouldn't this problem be consistent every time? The situation now is that if a user logs in and only gets \\server2\Home$\ mapped... he/she can just log off/on and the problem is solved... strange...

      Im gonna loose sleep over this tonight...
      Greetings from
      Petter C.


      • #4
        Re: Login script / map home folder.

        I have this too and never found a solution. My workaround is to enable "Always wait for the network at computer startup and logon"

        Must be a bug with using home folders + redirection.


        • #5
          Re: Login script / map home folder.

          Most likely what is happening is that the variable UserString is not being properly defined in the script.

          Comment out the line On Error Resume Next, and run the script manually.
          When the wrong path would have been mapped, you now probably get the following error (??),
          Error : Could not create object named "WScript.Network"
          Code : 8007007F

          Check the version of the Windows script host,
          if it is Windows Script 5.6 or 5.7, reinstall that version of WSH for testing on one of the computers.
          Download: 5.6 (make sure to install the correct Language for your OS) or, version 5.7

          To determine the wsh version installed, you type: cmd /k Cscript |find /i "Windows Script Host"

          The script you showed is not the complete script? because else you should clean the code a bit.

          To workaround the WScript.Network issues, use the following code to define UserString variable:
          UserString = WshShell.ExpandEnvironmentStrings("%UserName%")


          This posting is provided "AS IS" with no warranties, and confers no rights.


          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts


          • #6
            Re: Login script / map home folder.

            This is the complete script. I have taken this over from a previous administrator and I don't really know much about VB-scripting...

            I could really need some pointers
            Greetings from
            Petter C.


            • #7
              Re: Login script / map home folder.

              The Home folder of the user should be mapped via ADUC -> User properties / Profile tab
              Connect: U: To: \\server2\Home$\%username%

              Then, don't use the same drive letter again in the logonscript.

              Basically, the home folder is just the "Current Working Directory" for the user - it is searched before searching in other paths.

              To redirect the location of 'My Documents' you should configure a Folder re-direction policy.
              If you don't have edited the 'Home folder', then you can use a logon script to map a drive letter to the redirected 'My Documents' folder.

              Since you have already mapped U: to the 'Home folder' in ADUC, you shoudn't map U: again with the script. Unfortunately previous executions of the script could already have created a persistent drive mapping.
              To reverse this, use the following script as the logonscript:
              Option explicit
              Dim WshNetwork, clDrives, netDrives, i, strUser
              Set WshNetwork = WScript.CreateObject("WScript.Network")
              'Delete network drives that could once have been set as persistent,
              Set clDrives = WshNetwork.EnumNetworkDrives
              netDrives = clDrives.Count : If netDrives > 0 Then
                For i = 0 to netDrives -1 Step 2
                  WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
                wscript.sleep 800
              End If
              WshNetwork.MapNetworkDrive "O:", "\\server1\Operations", False
              WshNetwork.MapNetworkDrive "P:", "\\server1\Production", False
              strUser = WshNetwork.UserName
              WshNetwork.MapNetworkDrive "U:", "\\server2\home$\" & strUser, False
              Notice that I have left out the On Error Resume Next. This line shouldn't be just used in a logonscript without you realy capture errors for error-handling. So if there is a problem creating the object "WScript.Network" or something else, you will now get a error pop-up telling you (the user who is logging on) exactly what the problem is.


              This posting is provided "AS IS" with no warranties, and confers no rights.


              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts


              • #8
                Re: Login script / map home folder.

                I am not a scripter but I have had issues in the past where users on certain machines wouldn't be able to map to their Home folders but would be moved to the default share and that was through using the AD properties to set the Home drive.

                To resolve, as it was intemittent, I just removed the user account from their Home folder on the file share and added them back in. Problem solved.