powershell 中的目标路径在创建快捷方式时的问题 [英] Issues with Target Path in powershell in creating a short cut

查看:23
本文介绍了powershell 中的目标路径在创建快捷方式时的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在公共桌面上为用户创建快捷方式,但此快捷方式的目标路径导致了一些问题.

I am trying to create a short cut on public desktop for users, but this target path for this short cut is causing some issues.

$wshshell = New-Object -ComObject WScript.shell

$desktop = [System.Environment]::GetFolderPath("desktop")

$lnk = $wshshell.CreateShortcut("$desktop\CLMCPDEDEV.lnk")

$lnk.TargetPath = "C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe" "configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg"

我在另一个文件夹中有配置文件,而 exe 位于不同的路径中.我是 Power Shell 的新手,如何绕过 "C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe""configfile=c 之间的空间:\development-installs\web-enabler-config\CLMCPDEDEV.cfg"?当我手动执行此操作时,这是完整的捷径.非常感谢任何指导.

I have the config file in another folder and exe is in a different path. I'm new to power shell, how do I bypass that space between "C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe" and "configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg"? That's the full short cut path when I do this manually. Any guidance is much appreciated.

推荐答案

引用自 CreateShortcut 方法文档:

一个常见的问题是将参数放在快捷方式对象,它不起作用.快捷方式的所有参数必须放在 Arguments 属性中.

A common problem is putting arguments in the TargetPath property of the shortcut object, which doesn't work. All arguments to the shortcut must be put in the Arguments property.

所以你必须这样做:

$wshshell = New-Object -ComObject WScript.shell

$desktop = [System.Environment]::GetFolderPath('Desktop')

$lnk = $wshshell.CreateShortcut((Join-Path -Path $desktop -ChildPath 'CLMCPDEDEV.lnk'))

$lnk.TargetPath = 'C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe'
$lnk.Arguments = 'configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg'

$lnk.Save()

这篇关于powershell 中的目标路径在创建快捷方式时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆