使用 shell.application 获取特殊文件夹
我需要在脚本中返回当前用户桌面的路径。现在我知道你可以用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
Shell。命名空间 (...).Self.Path
:您的意思是您不能使用
WScript.CreateObject(...)
因为WScript
未定义?如果是这样,您只需使用CreateObject("WScript.Shell").SpecialFolders("Desktop")
即可。请参阅 CreateObject 和 Wscript.CreateObject 有什么区别?。You need to use
Shell.Namespace(...).Self.Path
:Do you mean you can't use
WScript.CreateObject(...)
becauseWScript
is undefined? If so, you can simply useCreateObject("WScript.Shell").SpecialFolders("Desktop")
instead. See What is the difference between CreateObject and Wscript.CreateObject?.尝试命名空间方法:
Where &H10&是桌面的特殊文件夹常量。有关所有特殊文件夹常量的列表,请参阅 technet。
Try the namespace method:
Where &H10& is a special folder constant for the desktop. See technet for a list of all special folder constants.