我想运行以下命令: “ diskpart / s my_batch.bat”
批处理文件内容:
rescan
select disk 1
online disk
我想将所选磁盘更改为来自用户输入 我该怎么做? 我尝试过:
“选择磁盘%1”
就像在批处理文件中一样 但这没用,如何让磁盘部分接受用户输入
答案 0 :(得分: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