【问题标题】:geting special folders with shell.application使用 shell.application 获取特殊文件夹
【发布时间】:2011-11-08 13:52:28
【问题描述】:

我需要在脚本中返回当前用户桌面的路径。现在我知道你可以用 WScript 做到这一点。

var WshShell = WScript.CreateObject("WScript.Shell");
         strDesktop = WshShell.SpecialFolders("Desktop");

但是对于我的脚本,这将不起作用,因为我不能使用 WScript。但我可以使用 shell.application 对象,如下所示。

 dim objShell
        dim ssfWINDOWS
        dim objFolder

        ssfWINDOWS = 0
        set objShell = CreateObject("shell.application")
            set objFolder = objshell.BrowseForFolder(0, "Example", 0, ssfWINDOWS)
                if (not objFolder is nothing) then
                Set objFolderItem = objFolder.Self
                    g_objIE.Document.All("logdir").Value = objFolderItem.path
                end if
            set objFolder = nothing
        set objShell = nothing

语法是什么,而不是“BrowseForFolder”,我可以简单地返回当前用户桌面的路径?

IE换行

set objFolder = objshell.BrowseForFolder(0, "Example", 0, ssfWINDOWS)

等价于。

strDesktop = WshShell.SpecialFolders("Desktop");

干杯

亚伦

【问题讨论】:

    标签: vbscript path special-folders


    【解决方案1】:

    你需要使用Shell.@987654321@(...).Self.Path:

    Const ssfDESKTOPDIRECTORY = &h10
    Set oShell = CreateObject("Shell.Application")
    strDesktop = oShell.NameSpace(ssfDESKTOPDIRECTORY).Self.Path
    
    WScript.Echo strDesktop
    


    但是对于我的脚本,这将不起作用,因为我不能使用 WScript。

    你的意思是你不能使用WScript.CreateObject(...) 因为WScript 是未定义的?如果是这样,您可以简单地使用 CreateObject("WScript.Shell").SpecialFolders("Desktop") 代替。见What is the difference between CreateObject and Wscript.CreateObject?。

    【讨论】:

    • 干杯,那是完美的,您可能对第二点是正确的。为链接干杯非常有用。
    【解决方案2】:

    尝试命名空间方法:

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(&H10&)
    

    其中 &H10& 是桌面的特殊文件夹常量。有关所有特殊文件夹常量的列表,请参阅 technet。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 2011-12-08
      相关资源
      最近更新 更多