powershell - 命令提示符 powershell 命令以提升批处理文件传递参数
问题描述
从 cmd 我使用 powershell 命令来提升批处理脚本并传递参数。参数包含双引号,但我不知道为什么它不起作用。
这是我的命令:
powershell -command "Start-Process -FilePath 'C:\My Path\update.bat' -ArgumentList '\"My File.zip\"'"
上面的命令工作正常,我的批处理脚本接收双引号中的参数,但是当我将命令更改为提升使用时,我遇到-Verb Runas
了问题(批处理脚本打开,但立即关闭):
powershell -command "Start-Process -Verb Runas -FilePath 'C:\My Path\update.bat' -ArgumentList '\"My File.zip\"'"
解决方案
最终解决方案来自@Compo 上面的回复。当批处理脚本的路径也包含空格时,此解决方案对我有用并且可以处理。
set "Args=%*"
net file 1>nul 2>&1 || (powershell -Command ^
Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c \""\""%~f0\"" %Args:"=\""%\""'
goto :eof)
推荐阅读
- javascript - react-spring:使用 useChain 进行缩放和翻译
- vue.js - Vue2 - 路由级别的延迟加载不起作用?
- r - 如何仅针对每个文件中的某些值组合多个 .RDS 文件?
- c++ - 在 C++ 中运行项目时出现未定义的引用错误
- visual-studio - 您好,我有一个使用 specflow 用 c# 编写的自动化框架
- python - 如何并行计算天体运动?
- c++ - 如何转发声明在单独的头文件中相互引用的结构?
- spring - 如何使用 Scala 在可执行 Jar 中自动装配 Spring 配置?
- ssh - 无法将 VS Code 连接到 Linux 机器进行远程开发
- c++ - 尝试将对象传递给同一个模板类进行复制