Disconnect Mapped drive

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Disconnect Mapped drive

#1 Post by Matt Williamson » 19 May 2016 11:14

I need some help with a script to map a drive do some things then unmap the drive. It also has to be able to work across 2 domains. It has to be a random drive because certain drive letters are being used on one domain and not the other and I never know which will be used at any given point to hard code it in. I'm using Net Use * to do that but I can't figure out how to unmap the drive when I'm done running the script. Here is my excerpt that shows what I'm attempting to do. Right now, it is just deleting my F: drive which is where the script lives.

Code: Select all

::@echo off
setlocal enabledelayedexpansion
set "testing=0"

if "%testing%" EQU "1" (
   set "xmlpath=F:\Scripts\batch\EOD testing"
) ELSE (
   set "xmlpath=\\server1\developer\inetpub\Ftproot\XMLs"
)
set "curdir=%~dp0"
if exist "%temp%\filterEOD.txt" del "%temp%\filterEOD.txt"
  If /i "%userdomain%" equ "DEV" (
     set "dom=PROD"
      set /p useris=Enter your production user name:
     set /p pw=Enter your production password:
      set Map1=Net use * "%xmlpath%" !pw! /USER:!dom!\!useris! /PERSISTENT:NO
      !Map1!
   ) ELSE (
     set Map2=Net use * "%xmlpath%" /PERSISTENT:NO
      !Map2!
   )
::pushd "%xmlpath%" && !Map2! || !Map1!
dir /o:-d /a-d "%xmlpath%\*.xml" |find "/" >"%temp%\filterEOD.txt"
for /f %%a in ("echo %%~da") do echo net use %%~da /del /y
cd /d %curdir%
endlocal
exit /b

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Disconnect Mapped drive

#2 Post by Squashman » 19 May 2016 13:12

I just use PUSHD and POPD.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Disconnect Mapped drive

#3 Post by Matt Williamson » 19 May 2016 13:23

Squashman wrote:I just use PUSHD and POPD.


I can't. Pushd balks in DEV environment and it doesn't take domain or password info that I'm aware of. That's why I have to use Net Use in DEV and put in PROD credentials.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Disconnect Mapped drive

#4 Post by Squashman » 19 May 2016 13:25

This thread should enlighten you.
viewtopic.php?t=5247

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Disconnect Mapped drive

#5 Post by Matt Williamson » 19 May 2016 13:51

I am enlightened. Thank you very much!

Post Reply