简体   繁体   English

如何从任何地方自动挂载虚拟硬盘?

[英]How to automatically mount virtual hard disk from anywhere?

I have these 3 files in a folder and they are all located in C:\\Max : 我在文件夹中有这3个文件,它们都位于C:\\Max

attach.bat : attach.bat

@echo off
cd %~dp0
diskpart /s run.txt

run.txt : run.txt

select vdisk file="C:\Max\maximus.vhd" 
attach vdisk

maximus.vhd : a virtual hard disk drive which is mounted via the other 2 files. maximus.vhd :通过其他2个文件安装的虚拟硬盘驱动器。

How can attach.bat get the current directory location and write it to run.txt ? 如何attach.bat获取当前目录位置并将其写入run.txt


I know how to write to the txt files, but I can't find the current directory. 我知道如何写入txt文件,但是找不到当前目录。 I want to be able to mount this from anywhere on the fly and any directory. 我希望能够随时随地从任何目录挂载此文件。

For example: 例如:

echo select vdisk file="C:\Max\maximus.vhd" >> C:\Max\run.txt
echo attach vdisk >> C:\Max\run.txt

The solution is using %~dp0 to reference the drive and path of the batch file as Anton Tykhyy suggested. 解决方案是按照Anton Tykhyy的建议,使用%〜dp0引用批处理文件的驱动器和路径。

@echo off
echo select vdisk file="%~dp0maximus.vhd" 1>"%~dp0run.txt"
echo attach vdisk 1>>"%~dp0run.txt"
timeout.exe /t 2 /nobreak
cd /D "%~dp0"
diskpart.exe /s run.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM