How to clean up old connections before mapping a new drive?

9,715

The command is:

net use /d * /y

Share:
9,715

Related videos on Youtube

mahi
Author by

mahi

Updated on September 18, 2022

Comments

  • mahi
    mahi almost 2 years

    I have scripts on Windows Server 2008r2 that access specific resources on other server systems using limited credentials. If a person or other script has also accessed that system from this server with different credentials and didn't log out, scripts fail with Error 1219 "The network folder specified is currently mapped using a different user name and password"

    How to ensure that my script deletes all connections to this specific machine before trying to map a new drive?

    C:\> net use //server /d  
    

    doesn't work on its own. I can follow it up with net use and see that a drive is still shared:

    C:\> net use \\server /d
    \\server was deleted successfully.
    
    
    C:\> net use
    New connections will be remembered.
    
    
    Status       Local     Remote                    Network
    
    -------------------------------------------------------------------------------
    Disconnected           \\server\somedrive       Microsoft Windows Network
    The command completed successfully.
    

    The disconnected drive will still cause the same Error 1219.

    Can anyone suggest a more elegant solution than deleting an exhaustive list of all shares that exists on that machine?

    net use \\server\share1 /d
    net use \\server\share2 /d
    net use \\server\share3 /d
    etc...
    

    Also

    net use \\server\* /d
    

    fails with "connection not found".

  • mahi
    mahi almost 6 years
    I'm trying to delete all connections one specific \\server. I think net use /d * /y will delete all connections to all servers, right?
  • joeqwerty
    joeqwerty almost 6 years
    Yes it will. I didn't pick that up in your question. My bad.