问题描述
我需要在脚本中将路径返回到当前用户桌面.现在,我知道您可以使用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
未定义所以不能使用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获取特殊文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!