New
#1
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:
extSSD_D.bat:Code: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:
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.Code:@echo off set"newE=daten*" set"newD=extSSD*" 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 ) set"lettE=E" 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 pause
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:
but what if the drive letter is not assigned ...Code:powershell (New-Object -comObject Shell.Application).Namespace(17).ParseName(\"E:\").InvokeVerb(\"Eject\")
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.