如何使用 vbs 将快捷方式发送到公共桌面

如何使用 vbs 将快捷方式发送到公共桌面

按照指示SS64我已经创建了一个vbs来创建快捷方式

我的test.vbs

Set objShell = WScript.CreateObject("WScript.Shell")
   Set lnk = objShell.CreateShortcut("%HOMEDRIVE%\Users\Public\Desktop\test.lnk")
   
   lnk.TargetPath = "%HOMEDRIVE%\test\start.bat"
   lnk.Arguments = ""
   lnk.Description = "test"
   lnk.HotKey = "ALT+CTRL+F"
   lnk.IconLocation = "%HOMEDRIVE%\test\test.ico, 0"
   lnk.WindowStyle = "1"
   lnk.WorkingDirectory = "%HOMEDRIVE%\test\"
   lnk.Save
   'Clean up 
   Set lnk = Nothing

出去

Error: Could not save shortcut
"c:\test\%HOMEDRIVE%\Users\Public\Desktop\test.ink"

如果我将快捷方式的路径从 更改为"%HOMEDRIVE%\Users\Public\Desktop\test.lnk"则仅在文件夹test.ink内成功创建快捷方式test

如何在路径中创建快捷方式"%HOMEDRIVE%\Users\Public\Desktop\test.lnk"

答案1

解决了。​​这是正确的 vbs 代码

Set objShell = CreateObject("Wscript.Shell")
strDesktop = objShell.SpecialFolders("Desktop")
Set objShortcut = objShell.CreateShortcut(strDesktop & "\test.lnk")
objShortcut.TargetPath = "%HOMEDRIVE%\test\start.bat"
objShortcut.Description = "Start test"
objShortcut.WorkingDirectory = strDesktop
objShortcut.IconLocation = "%HOMEDRIVE%\test\test.ico, 0"
objShortcut.Save

来源:social.technet.microsoft.com

相关内容