2017-07-29 123 views
0

我正在尋找獲取快捷方式路徑的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

如何獲取瀏覽文件夾功能的快捷方式?

+0

我能理解什麼,請詳細介紹一下您的具體問題。 – GTAVLover

回答

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 

更新WRT評論:

給出:

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

sShortPath和goFS,做到:

sShortPath = goFS.GetFolder(objPath).ShortPath 
+0

我加了一些解釋。 –

相關問題