0

我需要在脚本中返回当前用户桌面的路径。现在我知道你可以用 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");

干杯

亚伦

4

2 回答 2

3

尝试命名空间方法:

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

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

于 2011-11-08T14:17:01.807 回答
3

您需要使用:Shell.Namespace(...).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")。请参阅CreateObject 和 Wscript.CreateObject 有什么区别?.

于 2011-11-08T14:17:39.753 回答