使用 shell.application 获取特殊文件夹

发布于 2024-12-14 02:22:05 字数 1062 浏览 0 评论 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");

干杯

亚伦

I need in a script to return the path to the current user desktop. Now I know you can do it with WScript.

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

But for my script this will not work as I cant use WScript. but I can use the shell.application object as below.

 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

what is the syntax so the rather than "BrowseForFolder" i can simple return the path of the current users desktop?

IE replace the line

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

with the equilivent of.

strDesktop = WshShell.SpecialFolders("Desktop");

Cheers

Aaron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯了 2024-12-21 02:22:05

您需要使用 Shell。命名空间 (...).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 有什么区别?。

You need to use Shell.Namespace(...).Self.Path:

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

WScript.Echo strDesktop

But for my script this will not work as I cant use WScript.

Do you mean you can't use WScript.CreateObject(...) because WScript is undefined? If so, you can simply use CreateObject("WScript.Shell").SpecialFolders("Desktop") instead. See What is the difference between CreateObject and Wscript.CreateObject?.

儭儭莪哋寶赑 2024-12-21 02:22:05

尝试命名空间方法:

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

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

Try the namespace method:

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

Where &H10& is a special folder constant for the desktop. See technet for a list of all special folder constants.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文