vbs all user desktop folder
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")
The script crashes on the last line
The error message is
Microsoft VBScript runtime error (开发者_JAVA百科59, 1) : Object doesn't support this property or method: 'objShell.SpecialFolders'
* script completed - exit code: 259 *
I used http://www.wisesoft.co.uk/scripts/vbscript_display_special_folder_locations.aspx as a reference.
When ObjShell
is a WScript.Shell
you can access its implemented SpecialFolders
but you then reassign it to an instance Shell.Application
which does not implement SpecialFolders
, hence the error.
strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop")
retrieves the path, then:
Set objFolder = objShell.Namespace(strCurrentDirectory)
fetches it as a shell item, for example after that:
msgbox objFolder.Title
would echo "Desktop"
精彩评论