windows 如何使用参数从命令行启动存储在 UNC 共享上的程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/302381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you start a program stored on a UNC share from the command line with parameters?
提问by Josh Kodroff
There's an in-house program we use and it's stored on a UNC share so that updates are transparent. I'd like to supply it some command line parameters like so:
我们使用了一个内部程序,它存储在 UNC 共享中,以便更新是透明的。我想为它提供一些命令行参数,如下所示:
\server\share\in_house_thingy.exe myusername mypassword
But I can't seem to get it to work in either CMD or PowerShell or via a shortcut.
但我似乎无法让它在 CMD 或 PowerShell 中或通过快捷方式工作。
Anyone got any ideas?
有人有任何想法吗?
采纳答案by Orihara
For a shortcut, change the target to be like:
对于快捷方式,将目标更改为:
"\server\share\in_house_thingy.exe" myusername mypassword
unless you really do want to have to use powershell to make this work.
除非你真的想不得不使用 powershell 来完成这项工作。
回答by Steven Murawski
You could use:
你可以使用:
$app = '\server\share\in_house_thingy.exe'
$arguments = 'myusername mypassword'
$process = [System.Diagnostics.Process]::Start($app, $arguments)
The $process object will give you a live process object if you want to get an exit code or other information from that process.
如果您想从该进程中获取退出代码或其他信息,$process 对象将为您提供一个活动进程对象。
回答by Orihara
use %~dp0
in a batch file for the current (unc) path including the trailing \
使用%~dp0
在批处理文件用于当前(UNC)路径包括尾随\
in a powershell script use this for the current (unc) path without trailing \
在 powershell 脚本中,将此用于当前(unc)路径,而无需尾随 \
##代码## = $myInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName(##代码##)
回答by Josh Kodroff
I just noticed that there's a .CMD file that's copying the file from the share to the temp directory and running it locally.
我只是注意到有一个 .CMD 文件,它将文件从共享复制到临时目录并在本地运行。
If y'all could just vote this answer up if there's no better solution, that'll work.
如果没有更好的解决方案,你们都可以投票给这个答案,那就行了。