查找快捷方式路径Vbs
问题描述:
我正在寻找获取快捷方式路径的VBS浏览功能。不幸的是,我尝试过的所有浏览功能只有文件夹路径,但不是快捷方式路径。我可以在对话框中看到快捷方式,但无法获取它的路径。查找快捷方式路径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
。
如何获取浏览文件夹功能的快捷方式?
答
使用的文件或文件夹对象的.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
更新WRT评论:
给出:
objPath = objFolderItem.Path ' it's a string not an object!
sShortPath和goFS
,做到:
sShortPath = goFS.GetFolder(objPath).ShortPath
+0
我加了一些解释。 –
我能理解什么,请详细介绍一下您的具体问题。 – GTAVLover