Disconnect network drive used for home directory

DevilsbaneDevilsbane Posts: 4,212Member
Recently there has been some problems where home drives are being mapped wrong. They should be mapped to [URL="file://\\server\folder\%username%"]\\server\folder\%username%[/URL] but for some users they are being mapped to [URL="file://\\server\folder"]\\server\folder[/URL] which then breaks dependancies that use the H: drive.

This is an easy fix, simply disconnect the H: drive and then remap it. When done through windows explorer, you are presented with the message "There are currently files open on H:... Do you want to disconnect anyway?" You can say yes and the drive is removed.

However, I am trying to script the disconnect and the remap. Net Use H: /delete doesn't work. You get the error "The device is being accessed by an active process." Is there an option in the command line to disconnect anyway?

net use H: /delete /yes and net use /delete /y do not work like some people on the internet say they do.

Thanks for your help
Decide what to be and go be it.

Comments

  • instant000instant000 Posts: 1,745Member
    According to Microsoft documentation, you cannot use "net use" to disconnect from a resource you are utilizing.

    Note: This documentation is for Windows XP

    Microsoft Corporation

    The main work around in this case, is this:

    1. Fix the Home drive on the user's profile in Active Directory

    If it's specified how it is normally, there is an attribute for "home drive" that specifies [URL="file://\\server\folder\%username%"]\\server\folder\%username%[/URL] for each user to point to a certain drive letter.

    Once you make the change in active directory, the user would be corrected, whenever they logged off/logged on again.

    I hope this points you in the right direction.

    EDIT: Just realized you might not use this feature, and instead utilize "logon scripts". In this case, just edit the logon script for the path for Drive H.

    EDIT2: Disregard. if the user has this mapping for them at logon, more than likely you (or whoever else created the user and assigned the logon script/home drive mappings) assigned it using Active Directory. This might be the quickest way to resolve this issue.
    Currently Working: CCIE R&S
    LinkedIn: http://www.linkedin.com/in/lewislampkin (Please connect: Just say you're from TechExams.Net!)
  • DevilsbaneDevilsbane Posts: 4,212Member
    Active Directory is already configured to connect H to [URL="file://\\server\folder\%username"]\\server\folder\%username[/URL]

    Usually this has been solved is by having them restart and it maps correctly. I'm just trying to devise this shortcut to disconnect/reconnect until the root of the problem can be found.
    Decide what to be and go be it.
  • DevilsbaneDevilsbane Posts: 4,212Member
    To give everyone an update on this, I have a batch file that runs a .vbs script which is able to force the unmapping. I then use just a standard net use command to map it correctly.

    If anyone encounters this same issue, let me know and I can help you out.

    Otherwise, does anyone have an idea why it doesn't map correctly in the first place? This has been happening here and there for awhile, but starting this week has become a bigger problem. Is it possible that when the logon is happening the %username% variable hasn't been set yet?
    Decide what to be and go be it.
  • undomielundomiel Posts: 2,818Member
    You could also try enabling always wait for network at computer startup and logon. This KB sounds like your exact problem: The Home Folder may be mapping incorrectly when logging on to a Windows XP-based computer
    Jumping on the IT blogging band wagon -- http://www.jefferyland.com/
  • CmsimhaCmsimha Posts: 2Registered Users ■□□□□□□□□□
    Devilsbane,
    Please, could you contact me? I have an issue in one of my servers and need to use the batch file that runs a .vbs script which is able to force the unmapping.

    I am a new user so can´t sent you a pm.

    Thanks,
    Claudio.
  • About7NarwhalAbout7Narwhal Posts: 761Member
    If you are using DFS you might want to double check your settings. The last company I worked for enabled DFS for a Windows 7 / XP network and everything went weird. Some people would map fine, others would not map at all, they would map and get "Access Denied" errors, etc etc. The DFS naming convention did not match GPOs that were in place. Just my 2 cents from experience.

    Good Luck!
  • DevilsbaneDevilsbane Posts: 4,212Member
    I dug up the scripts that I wrote. These didn't fix the problem (which is mostly gone now, rarely it will happen) but was a good use in the meantime.

    HDriveFix.bat
    @echo off
    REM Written by Devilsbane
    Title Fix H drive mapping
    
    echo Disconnecting H: Drive...
    wscript.exe HDriveFix.vbs             *I used an absolute path here, but deleted it for this posting, \\servername\share\ *
    ping 127.0.0.1 -n 2 >NUL              *This is my getto pause command, since not every workstation has all of the support tools installed*
    net use H: \\server\Share$\%username%
    echo Your H: drive has been mapped successfully.
    echo.
    pause
    


    HDriveFix.vbs
    ' Written by Devilsbane
    ' Date: July 12, 2011
    
    Dim net, objShell
    
    err.number = vbempty
    set net = wscript.CreateObject("Wscript.Network")
    On Error Resume Next
    net.RemoveNetworkDrive "H:", _
    True
    
    If err.number = vbEmpty then
    Set objShell = CreateObject("WScript.Shell")
    ElseIf err.number = -2147022646 then
    Wscript.Echo "H: Drive didn't exist, mapping H: Drive now"
    Else Wscript.echo "Unknown Error " & err.number
    End If
    
    Wscript.Quit
    


    In other words, the bat file calls the script to kill the H: drive, pauses briefly, reconnects it with the net use command, and then tells the user they are good to go.


    Note, anything inside the *'s was added as a comment for this post.
    Decide what to be and go be it.
  • ptilsenptilsen Posts: 2,835Member ■■■■■■■■■■
    So you never found the root cause?

    I have never encountered anything like this that wasn't caused by a conflicting GPO or the issue undomiel linked. Mapping home to \\server\folder\%username% should "just work." Did you run RSOP or GPResult and look for any other GPO drive maps (or GPOs with drive map scripts)?
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • DevilsbaneDevilsbane Posts: 4,212Member
    This was some time ago, and I'm not in the role anymore.

    It was bizarre, the issue had the potential to happen to everyone and didn't happen every login. The accounts were configured correctly in AD. I believe the culprit was due to a bandwidth issue. The 2 times I've had it happen to me since this issue 2 years ago was when I was logging in from home and connecting to the VPN after login. Yes, not the root cause but this script made life easier for many. I was on the helpdesk at the time, so it was never really my job to find the problem. But everything looked right from what I checked.
    Decide what to be and go be it.
  • About7NarwhalAbout7Narwhal Posts: 761Member
    All bets are off when it comes to VPN. We always had people who didn't get their drives. I had just assumed that was life and moved on. lol
  • CmsimhaCmsimha Posts: 2Registered Users ■□□□□□□□□□
    Thanks a lot for your help.
Sign In or Register to comment.