2011-11-08 112 views
0

我需要在脚本中将路径返回到当前用户桌面。现在我知道你可以用WScript来做。使用shell.application创建特殊文件夹

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替换的equilivent线

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

strDesktop = WshShell.SpecialFolders("Desktop"); 

干杯

亚伦

回答

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是undefined?如果是这样,您可以简单地使用CreateObject("WScript.Shell").SpecialFolders("Desktop")。见What is the difference between CreateObject and Wscript.CreateObject?

+0

欢呼,这是完美的,你可能是正确的关于第二点。欢呼的链接非常有用。 – DevilWAH

3

尝试命名方法:

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

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