简体   繁体   English

如何从命令行使用参数启动存储在UNC共享中的程序?

[英]How do you start a program stored on a UNC share from the command line with parameters?

There's an in-house program we use and it's stored on a UNC share so that updates are transparent. 我们使用的是内部程序,它存储在UNC共享中,以便更新透明。 I'd like to supply it some command line parameters like so: 我想提供一些命令行参数,如下所示:

\\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? 有人有任何想法吗?

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对象将为您提供实时进程对象。

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来完成这项工作。

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)路径而不尾随\\

$0 = $myInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)

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. 如果没有更好的解决方案你们都可以投票给这个答案,那就行了。

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

相关问题 从命令行启动邮件程序并使用反斜杠设置主题 - Start a mail program from command line and set subject with backslash 如何从Windows中的命令行启动可执行文件 - how to start executable from command line in windows 如何从命令行启动CouchDB - How to start CouchDB from command line 如何从命令行启动该程序? - How to launch this program from the command line? 使用带有传递给启动程序的参数的“start”命令 - Using the "start" command with parameters passed to the started program 如何从命令行参数将命令推送到功能参数? - How to push a command to the function parameters from the command line arguments? 在Windows的命令提示符中使用start命令执行程序时,如何将多个参数传递给程序? - How to pass multiple parameters to a program while executing it using start command in command prompt in windows? 如何从MinGW Shell将任意命令行参数传递给本机Windows程序? - How do I pass an arbitrary command line argument to a native Windows program from a MinGW shell? 如何在不打开新 cmd 窗口的情况下从命令行启动程序? - How do I launch a program from command line without opening a new cmd window? 如何在不复制的情况下从 Windows 命令行合并两个目录或移动替换? - How do you merge two directories, or move with replace, from the windows command line without copying?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM