Script for (u)mounting partition and open explorer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Script for (u)mounting partition and open explorer

#1 Post by doscode » 21 Apr 2023 15:45

Hello,
I use Windows XP still. I would like to do the following. I have a file like video and I select it in file explorer. I copy it in context menu or by ctrl+c. Now I want to click on icon on my desktop to run a script. The script must to do the following: To mount a certain partition (now there are three disks connected and I can do this manually in MS Disk Manager). So I need to add a letter Y: to the partition I think it is 3rd partition (NTFS). Then I need to open certain folder like SHARED in File rxplorer - so not to do this manually. Then I need to paste the file here. And unmount the partition.

OR - if possible better solution of my problem would be: Do not open the Explorer, but copy the file here: Y:\_SHARED_ ... Because the file to be copied is already marked. I think this would be definitely perfect solution. And then unmount the partition. The last step is very important for me. Can you help me with this. I think I can find how to mount or unmount but not sure how to copy the file - the ctrl+C marked file.

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Script for (u)mounting partition and open explorer

#2 Post by DOSadnie » 24 Apr 2023 15:31

Here is my old BAT that I was using until I replaced my archive HDD with SSD [thus no longer had to stop the noise being generated by it]

You will have to read through it dough, to know how to adjust it to your needs

Code: Select all

:: This will unmount the drive with the letter X assigned to it
::
::
::
:: To write down such a BAT [and its counterpart] for any drive [except probably for C] you need to:
::
:: 1] Open up the Command Prompt as Administrator
::
::
::
:: 2] Run command
::
::    mountvol
::
::
::
:: 3] Copy the whole long gibberish Volume Name appearing above a given drive. It starts with
::
::     \\?\{
::
::     and ends with
::
::     }\
::
::
::
:: 4] Run command
::
::    mountvol @: /p
::
::    where @ stands for the letter of the drive. This will dismount that drive. Do not use >>/d<< which only removes the drive letter assignment
::
::
::
:: 5] Run command
::
::    mountvol @: /p \\?\Volume{########-####-####-####-############}\<<
::
::    where @ stands for the letter of the drive and all those ## stand for its name. This will mount back that drive
::
::
::
:: 6] In case of problems please refer to:
::
::    https://superuser.com/questions/704870/mount-and-dismount-hard-drive-through-a-script-software
::
::    www.instructables.com/id/VBScript-Working-with-mounted-drives



:: And so the current commands are
::
:: mountvol X: /p
::
:: mountvol X: \\?\Volume{9647db15-ae52-43d4-bf80-5adb74be5984}\
::
:: But the problem with all of this is that mountvol only takes case of the mount state and disregards the spinning thus noise [thus the main reason for using such BAT]. Although recently it started to also spin the drive down
::
::
::
:: And also, for a BAT with these commands to work it has to be run a Administrator. And instead of right clicking the BAT and using the "Run as administrator" shell entry, an ordinary shortcut to such BAT can be created for which
::
::    Properties > Shortcut > Advanced > Run as administrator
::
:: checkbox can be selected
::
:: [However if CMD is run as Administrator then strangely somehow only the dismount command works when executed within it]



mountvol X: /p



exit



:: An alternative way to dismount is to use such a BAT:
::
::
::
:: @echo off
::
:: REM Change this to the drive you want to unmount
:: set drive=C:
::
:: echo Unmounting Drive...
:: mountvol %drive% /p
:: echo Drive Unmounted
::
:: pause
:: exit



:: An alternative way to mount back is to use such a BAT:
::
::
::
:: @echo off
::
:: REM Change this to the drive letter you want to mount the drive to
:: set drive=X
::
:: REM Change this to the Volume Name of the drive you want to mount
:: set volume=\\?\Volume{########-####-####-####-############}\
::
:: :start
:: echo Mounting Drive...
:: mountvol %drive%: %volume%
:: echo Drive Mounted
::
:: pause
:: exit

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Script for (u)mounting partition and open explorer

#3 Post by DOSadnie » 24 Apr 2023 15:51

You might also want to read this discussion https://community.mp3tag.de/t/achieving ... -10/45914/ and try out using mentioned in it freeware revoSleep for easy temporary mounting and dismounting of volumes

Post Reply