0

我正在使用 VBscript 修改快捷方式的目标路径,但我无法这样做。当我运行脚本时,我没有收到任何错误,但似乎脚本没有做任何事情,即目标路径没有改变。这是我的脚本

Private Sub Change_ShortCut(TargetPath, ShortCutPath, ShortCutname, WorkPath, ServerName, PortNumber, ServiceName, ExecVar)
Dim VbsObj
Dim userName
Dim hostName

 ' Get user name and host name from another method
 Get_UserName userName, hostName 

Const ALL_USERS_DESKTOP = &H19&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ALL_USERS_DESKTOP)
Set objFolderItem = objFolder.ParseName("App1.lnk")
Set objShellLink = objFolderItem.GetLink
Wscript.Echo objShellLink.Path
objShellLink.Path = TargetPath & ServerName & " " & PortNumber & " " & ServiceName & " " & userName & " " & hostName & " 20 -exec=" & """" & "\""" & ExecVar & "\""" &"""" 
objShellLink.Save

End Sub
4

1 回答 1

2

你太努力了。改用一个WshShell对象:

Set fso = CreateObject("Scripting.FileSystemObject")
Set sh  = CreateObject("WScript.Shell")

lnkpath = fso.BuildPath(sh.SpecialFolders("AllUsersDesktop"), "App1.lnk")
Set lnk = sh.CreateShortcut(lnkpath)
lnk.TargetPath = TargetPath & ServerName & " " & PortNumber & " " & ServiceName _
  & " " & userName & " " & hostName & " 20 -exec=""\""" & ExecVar & "\"""""
lnk.Save

如果您有域环境,则使用组策略首选项可能是更新快捷方式的更好方法。

于 2013-10-14T22:06:16.347 回答