![](/img/trans.png)
[英]Is it possible for a Perl script running on a Unix/Linux platform to create Windows Shortcuts?
[英]Cannot create Windows shortcuts in PowerShell on Linux
我想使用腳本在Windows操作系統(.lnk)下創建快捷方式。
在Windows環境中,我選擇了PowerShell,編寫了腳本,成功創建了.lnk。
$shell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop')
$shortcut = $shell.CreateShortcut("$desktop\clickme.lnk")
$shortcut.TargetPath = "C:\Users\scc\Desktop\linkfolder"
$shortcut.IconLocation = "shell32.dll,004"
$shortcut.Save()
但是我的在線運行環境是Linux。
幸運的是,我發現PowerShell在2016年進行了多平台移植,是的,它可以支持Linux。 我找到它,下載並安裝。 在Linux下,我可以在PowerShell命令窗口中運行一些基本命令。
發生執行階段錯誤! 當我運行第一行代碼時:
$shell = New-Object -ComObject WScript.Shell
錯誤消息是:
New-Object : Unable to load DLL 'api-ms-win-core-com-l1-1-0.dll': The specified module or one of its dependencies could not be found. (Exception from HRESULT: 0x8007007E) At line:1 char:10 + $shell = New-Object -ComObject WScript.Shell + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-Object], DllNotFoundException + FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.NewObjectCommand
根據提示,似乎缺少與WScript相關的模塊。 缺少DLL文件。
我的要求是在Linux下運行Java程序以創建Windows格式的快捷方式。 (存儲在網絡磁盤中的文件系統為btrfs,並可以提供SMB \\ AFP \\ NFS \\ FTP這些文件服務)
是的,這種需求似乎很奇怪,如果您有新的解決方案和想法,請告訴我或與我討論。
我有一個大膽的主意:我可以使用SMB協議來創建.lnk文件嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.