我想运行以下命令:“diskpart / s my_batch.bat”
批处理文件内容:
rescan
select disk 1
online disk
我想更改所选磁盘来自用户输入我该怎么办?我试过了:
“选择磁盘%1”
就像在批处理文件中但它没有工作,如何让磁盘部分接受用户输入
动态创建.script
文件(与批次相同的位置/名称)
并传递给Diskpart
。自升式(仅部分测试)。
:: Q:\Test\2019\03\19\SO_55242922.cmd
@echo off & setlocal EnableExtensions DisableDelayedExpansion
net file 1>nul 2>&1 || (powershell -ex unrestricted -Command ^
"Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~f0 %*'"
goto :eof)
:: Put code here that needs elevation
if "%~1" equ "" goto :ListDisk
( Echo rescan
Echo select disk %1
Echo online disk
Echo Exit
) > "%~dpn0.script"
Goto :ExecViewOutput
:ListDisk
( Echo list disk
Echo Exit
) > "%~dpn0.script"
:ExecViewOutput
diskpart /s "%~dpn0.script" >"%~dpn0.log"
type "%~dpn0.log"
Pause
:: optionally delete the script/log file
:: Del %~dpn0.log" "%~dpn0.script"
Exit /B 0