查找快捷方式路径Vbs

时间:2017-07-29 10:18:42

标签: vbscript wmi

我正在寻找一个获取快捷方式路径的VBS浏览功能。不幸的是我试过的所有浏览功能只有文件夹路径,但不是快捷方式路径。我可以在对话框中看到快捷方式,但无法获得它的路径。

是否有人有这种功能?

strComputer = "."
Const ALL_OPTIONS = &H4000

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder (0, "Select a folder:",ALL_OPTIONS,(16))

If objFolder Is Nothing Then
    Wscript.Quit
Else
    Set objFolderItem = objFolder.Self
End If

objPath = objFolderItem.Path

此功能提供真实的文件夹路径,但当我选择快捷方式时,它会返回null

如何通过浏览文件夹功能获取快捷方式路径?

1 个答案:

答案 0 :(得分:0)

使用文件或文件夹对象的.ShortPath属性:

Option Explicit

Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim f
Set f = goFS.GetFolder(".") : WScript.Echo f.Path, f.ShortPath
Set f = goFS.GetFile(WScript.ScriptFullName) : WScript.Echo f.Path, f.ShortPath

输出:

cscript //nologo "45388073-pi pa po.vbs"
C:\Users\eh\work C:\Users\eh\work
C:\Users\eh\work\45388073-pi pa po.vbs C:\Users\eh\work\453880~1.VBS

更新评论:

下式给出:

objPath = objFolderItem.Path ' it's a string not an object!

sShortPath和goFS,执行:

sShortPath = goFS.GetFolder(objPath).ShortPath