mount/unmount external drive instead of internal drive automatically

  1. Posts : 17
    W10 W8.1 W7

    mount/unmount external drive instead of internal drive automatically

    Hi to all,
    I have lot of portable tools and data on my external drive which I use with my work and home PC. Both PCs have one built in drive with a C and D partition.
    My desktop shortcurts point to D:\myPortableProgsPath\... to call those portable programs.
    The local built in D: has just a subset (copy) of the ext. drive which I sync occasionally.

    So far I created a desktop shorcut to mount the ext.Drive like this:
    C:\Windows\System32\runas.exe /noprofile /user:adm /savecred  "C:\_D\bat\extSSD_D.bat"
    Mount external(partion name=extSSD) as D: and internal(partion name=daten) as E: . If external not present mount internal as D:
    @echo off
    mountvol d:/D
    mountvol e:/D
    for/f "tokens=2,3 delims= "%%A in('echo list volume ^| diskpart ^| findstr "%newD%"')do(
    set drvD=%%B
    (echo select volume %%A
    echo assign letter=D)| diskpart >nul
    if/I [%drvD%] EQU [](set"lettE=D"& echo.& echo !!!!!!!!!!!!!!!!!!!%newD%not found !!!!!!!!!!!!!!!!!!!)
    for/f "tokens=2,3 delims= "%%A in('echo list volume ^| diskpart ^| findstr "%newE%"')do(
    (echo select volume %%A
    echo assign letter=%lettE%)| diskpart >nul
    echo list volume | diskpart
    Now I thought about a 2nd shorcut (and .bat) to safely eject the external and call the above .bat to remount the internal D again.

    1 That would OK, if there is a way to call the Win10 built in eject from a .bat (I am to old to learn PowerShell ;-). I read those.

    1a And I tried mountvol /D, but this unmounts the drive not matter a file is opened ! It just removes the drive letter and does not unmount the device.
    mountvol /P like diskpart REMOVE ALL DISMOUNT unmounts the device BUT if one reconnects the drive you have to manually assign a letter again :-(...

    1b this works:
    powershell (New-Object -comObject Shell.Application).Namespace(17).ParseName(\"E:\").InvokeVerb(\"Eject\")
    but what if the drive letter is not assigned ...

    This would be great if there is a methode that works on the volume or volume label - any idea ??

    2 What would be great too:
    Whenever my external drive is connected, I want it to substitute D: and when diconnected the second partition of the builtin drive should be D: again. The thing is that there are several kinds od disconnect that could happen... e.g. eject via taskbar (tray) safe eject, during power off or accidentenly,... so maybe soltion 1 is the more secure way to go.

    - - - Updated - - -

    no ideas ;-) ?
    Last edited by 5ggggg; 15 Jun 2020 at 12:31.
      My Computer

  2. Posts : 2,803
    Windows 11 Pro, 22H2

    For an external drive that I always need to have available in the same location, I prefer to use a mount point rather than assigning a drive letter. That way I am always guaranteed that the drive will be available in the same location every time I connect it and I don't have to worry about things like drive letters changing. See this article for the details:

    Mount Drive to a Folder in Windows 10
      My Computers

  3. Posts : 17
    W10 W8.1 W7
    Thread Starter

    I have a minimum set of port progs always available which I have on a built partition/folder like d:\sources\progA.

    When I connect my ext. drive it would be great if this could be automounted to d: instead of the lokal drive. This can be done by scripting like mine above....
    In Linux a mountpoint can substitute an existing directory. It automounts the drive whereever one wants (has defined before) and when the drive is unmounted the dir (which was substituted) is present again.
    This would perfectly solve my demand.
      My Computer

  4. Posts : 61,846
    64-bit Windows 11 Pro for Workstations

    Hello @5ggggg,

    You might see if the commands used in the tutorial below may be able to help with what you are wanting to do to mount and unmount the drive on demand.

    How to Mount and Unmount a Drive or Volume in Windows
      My Computers

  5. Posts : 17
    W10 W8.1 W7
    Thread Starter

    THX Shawn, I used mountvol and diskpart in my script above. But that is not the solution :-(
      My Computer

  6. Posts : 2,803
    Windows 11 Pro, 22H2

    So is mounting it to an empty folder not a workable solution for you?

    If not, could I suggest simply using a drive letter later in the alphabet? This way, the insertion of other drives won't hijack that drive letter. For example, if you assign drive letter T: to it, you would have to plug in quite a few drives before anything else tries to use T:.
      My Computers

  7. Posts : 17
    W10 W8.1 W7
    Thread Starter

    I want all my desktop shortcuts point to drive:\sources\... whereas the letter is not the prob. I would like to see the subset of my port Apps stored at the same point as when I connect the ext. drive which then should automatically substitute them.
      My Computer


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 01:17.
Find Us

Windows 10 Forums