我似乎无法让 WShell 返回 objShortcut.TargetPath 的值,尽管它可以很好地传递全名。
我一直在阅读 WShell 可能会遇到远程磁盘问题,而我一直在使用外部驱动器。
在我的 C: 驱动器上的快捷方式上测试了它,文件位于我的 C: 驱动器上,我发现它仍然不起作用。它不回显目标路径,而是回显一个空白值。
已编辑。感谢您的提示。
getshorty.vbs
Dim objWSHShell
set objWSHShell = CreateObject("WScript.Shell")
Set wshShell = WScript.CreateObject("WScript.Shell")
strTargetPath=objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
Set objShortcut = wshShell.CreateShortcut(strTargetPath)
WScript.Echo objShortcut.TargetPath
Set objShortcut = Nothing
Set wshShell = Nothing
最佳答案
这是一个创建快捷方式的函数:
Call Shortcut("C:\The Absolute Path of your application goes here","Name of your Shortcut")
'*********************************************************************************
Sub Shortcut(PathApplication,Name)
Dim objShell,DesktopPath,objShortCut,MyTab
Set objShell = CreateObject("WScript.Shell")
MyTab = Split(PathApplication,"\")
If Name = "" Then
Name = MyTab(UBound(MyTab))
End if
DesktopPath = objShell.SpecialFolders("Desktop")
Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & Name & ".lnk")
objShortCut.TargetPath = Dblquote(PathApplication)
ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,-25"
objShortCut.Save
End Sub
'*********************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************
关于vbscript - TargetPath 为空 - 在远程驱动器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32421790/