通过shell.application获取特殊文件夹 [英] geting special folders with shell.application

查看:465
本文介绍了通过shell.application获取特殊文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在脚本中将路径返回到当前用户桌面.现在,我知道您可以使用WScript做到这一点.

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");

但是对于我的脚本,这将无法正常工作,因为我无法使用WScript.但是我可以使用如下的shell.application对象.

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

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

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

IE替换行

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

具有等价物.

strDesktop = WshShell.SpecialFolders("Desktop");

欢呼

亚伦

推荐答案

您需要使用Shell.Namespace(...).Self.Path:

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


但是对于我的脚本,这将无法正常工作,因为我无法使用WScript.

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

您是说因为WScript未定义所以不能使用WScript.CreateObject(...)吗?如果是这样,您可以简单地使用CreateObject("WScript.Shell").SpecialFolders("Desktop")代替.参见 CreateObject和Wscript.CreateObject有什么区别?.

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?.

这篇关于通过shell.application获取特殊文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆