Announcement

Collapse
No announcement yet.

Manually mapped drive won't unmap with script.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Manually mapped drive won't unmap with script.

    I have a bizarre issue.
    I'm making a log off script to remove mapped drives, but it only works on drives created by a script. Any manually map drives persist.

    This is an example of my drive mapping scripts:
    Code:
    Option Explicit
    Dim objNetwork, strDriveLetter, strNetworkPath
    strDriveLetter = "T:"
    strNetworkPath = "\\Server\path"
    
    On Error Resume Next
    
    Set objNetwork = CreateObject("WScript.Network")
    
    ' Section which removes strDriveLetter
    objNetwork.RemoveNetworkDrive strDriveLetter
    
    ' Section which adds strDriveLetter
    objNetwork.MapNetworkDrive strDriveLetter, strNetworkPath
    
    Wscript.Quit
    
    ' End of Script

    This is my script for unmapping all mapped drives:
    Code:
    On Error Resume Next
    
    Set objNetwork = CreateObject("Wscript.Network")
    
    Set colDrives = objNetwork.EnumNetworkDrives
    
    For i = 0 to colDrives.Count-1 Step 2
        objNetwork.RemoveNetworkDrive colDrives.Item(i)
    Next
    It works perfectly on any mapping done by my scripts, but doesn't work on maps done by hand. I can right click the mapped drives and disconnect them.

    Any ideas?

  • #2
    Re: Manually mapped drive won't unmap with script.

    try replace this line :

    objNetwork.RemoveNetworkDrive colDrives.Item(i)

    with this:

    objNetwork.RemoveNetworkDrive colDrives.Item(i), True, True
    Any advice is given in good faith and without warranty.
    Please give reputation points where appropriate.

    Comment


    • #3
      Re: Manually mapped drive won't unmap with script.

      Also remove the on error resume next when debugging.
      Marcel
      Technical Consultant
      Netherlands
      http://www.phetios.com
      http://blog.nessus.nl

      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
      "No matter how secure, there is always the human factor."

      "Enjoy life today, tomorrow may never come."
      "If you're going through hell, keep going. ~Winston Churchill"

      Comment


      • #4
        Re: Manually mapped drive won't unmap with script.

        Awesome!

        Originally posted by largo View Post
        try replace this line :

        objNetwork.RemoveNetworkDrive colDrives.Item(i)

        with this:

        objNetwork.RemoveNetworkDrive colDrives.Item(i), True, True

        Comment

        Working...
        X