Powershell快捷方式创建不起作用 [英] Powershell shortcut creation isn't working

查看:35
本文介绍了Powershell快捷方式创建不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个脚本可以自动安装一些软件.安装软件后,我创建了一些重要应用程序的快捷方式,这些快捷方式会出现在桌面上.这是我的代码.

So I have this script that is automating the installation of some software. After I install the software, I create shortcuts to some important applications these shortcuts appear on the desktop. Here is my code.

$ConfigureExeSource = "C:\Program Files (x86)\SiteKiosk\Configure.exe"
$ConfigureLoc = "C:\Users\Public\Desktop\Configure.lnk"

$StartSiteKioskExeSource = "C:\Program Files (x86)\SiteKiosk\SiteKiosk.exe"
$StartSiteKioskLoc = "C:\Users\Public\Desktop\SiteKiosk.lnk"

$CheckKioskExeSource = "C:\Users\Public\Documents\checkkiosk.exe"
$CheckKioskLoc = "C:\Users\Public\Desktop\checkkiosk.lnk"

#copying to desktop
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($ConfigureLoc)
$Shortcut.TargetPath = $ConfigureExeSource
$Shortcut.Save()
Write-Host "Created Configure.exe Shortcut"

$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($StartSiteKioskLoc)
$Shortcut.TargetPath = $StartSiteKioskExeSource
$Shortcut.Save()
Write-Host "Created Sitekiosk.exe Shortcut"

$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($CheckKioskLoc)
$Shortcut.TargetPath = $CheckKioskExeSource
$Shortcut.Save()
Write-Host "Created Checkkiosk.exe Shortcut"

然后我生成了快捷方式,之后我测试了每个快捷方式.这导致除了配置快捷方式之外,所有这些都可以工作.

I then get the shortcuts generated, After that I tested each one. This resulted in all of them working except the Configure shortcut.

我手动创建了一个配置快捷方式,以确保我有正确的路径,我做到了.然后我比较了其他属性,我发现我的 powershell 的 startIn 属性是空白的,但在手动创建的属性中填充了C:\Program Files (x86)\SiteKiosk".我将其复制到了 powershell 中,并且成功了.

I manually created a configure shortcut to make sure I had the right path and I did. I then compared other properties and I found that the startIn Property was blank for my powershell one but filled with "C:\Program Files (x86)\SiteKiosk" in the manually created one. I copied that over to the powershell one and it worked.

现在我不知道发生了什么,因为 sitekiosk 快捷方式在没有填写字段的情况下工作,但配置人员出于某种原因想要它,否则它将无法工作.有谁知道我如何修复我的代码以正确生成有效的快捷方式,即使修复只是为快捷方式生成该字段.我环顾四周,没有找到在快捷方式中填充 startIn 字段的方法.

Now I have no Idea whats going on because the sitekiosk shortcut worked without the field filled in but the configure one wants it for some reason or else it won't work. does anyone know how I could fix my code to properly generate a shortcut that works, even if the fix just generates that field for the shortcut. I've looked around and haven't found a way to fill the startIn field in a shortcut.

PS:我尝试上传照片,但由于我的代表低于 10 人,stackoverflow 不允许我上传,但如果有人认为有帮助,我可以将它们上传到 imgur.

PS: I tried uploading photos but stackoverflow didn't let me as I have below 10 rep, I can upload them to imgur though if anyone thinks it would help.

推荐答案

MSDN 参考页面,您需要设置 WorkingDirectory 属性.

As seen in the MSDN reference page you would want to set the WorkingDirectory property.

$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($ConfigureLoc)
$Shortcut.TargetPath = $ConfigureExeSource
$Shortcut.WorkingDirectory = "C:\Program Files (x86)\SiteKiosk"
$Shortcut.Save()

这篇关于Powershell快捷方式创建不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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