我正在使用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
答案 0 :(得分: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
如果您有域环境,使用Group Policy Preferences可能是更新快捷方式的更好方法。