vbs所有用户桌面文件夹

时间:2011-05-20 14:54:02

标签: file scripting vbscript windows-scripting

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strCurrentDirectory)
Set objFolderItem = objFolder.Self
strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop")

脚本在最后一行崩溃

错误消息是

  

Microsoft VBScript运行时错误(59,   1):对象不支持此功能   财产或方法:   'objShell.SpecialFolders'

     

*脚本已完成 - 退出代码:259 *

我使用http://www.wisesoft.co.uk/scripts/vbscript_display_special_folder_locations.aspx作为参考。

1 个答案:

答案 0 :(得分:3)

ObjShellWScript.Shell时,您可以访问其已实施的SpecialFolders,但您会将其重新分配给未实现Shell.Application的实例SpecialFolders,因此错误。

strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop")

检索路径,然后:

Set objFolder = objShell.Namespace(strCurrentDirectory)

将其作为shell项获取,例如在此之后:

msgbox objFolder.Title

会回复"Desktop"