Windows 7 - programmatically, how can I show just the "Documents" folder

DWStovall
DWStovall used Ask the Experts™
on
I want to use vbscript to put just the "Documents" folder on the Desktop.

In our environment, users only need access to the "Documents' folder, not all of the folders in "User's Files"

In an existing script for XP, I use the attached lines of vbscript to show the "My Documents" icon.

In Windows 7, this same code puts the "User's Files" on the Desktop - that's more than we want.  We just want the "Documents" folder on the desktop.


strRegWriteKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu\{450D8FBA-AD25-11D0-98A8-0800361B1103}"
   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"
   strRegWriteKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel\{450D8FBA-AD25-11D0-98A8-0800361B1103}"
   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"
   objShell.SendKeys "{F5}"

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
That is because in Vista and Windows 7 the user folder is kind of equivalent to the XP My Documents.  The documents folder in Vista/Win7 does not contain all the items that XP documents does (like My Pictures, My Music, etc).  If you really want to limit it to just the documents on Windows 7, then we will need to adjust your script to hide the user folder and then send a shortcut to the desktop for the documents folder.  

Below is some code you can add that will hide the user folder and add a shortcut to the documents folder.

-Bear




Dim objShell, objFolder, objFldrItem
Dim objAppl, objLink, objDesktop

strRegWriteKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu\{645FF040-5081-101B-9F08-00AA002F954E}"
   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"
   strRegWriteKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel\{645FF040-5081-101B-9F08-00AA002F954E}"
   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"

Set objShell = WScript.CreateObject("WScript.Shell")
Set objAppl = CreateObject("Shell.Application")

' Grab the User's Documents Folder
Set objFolder = objAppl.Namespace(&H5&)	'Windows documents folder vista / My documents xp
Set objFldrItem = objFolder.Self

' Create the Desktop Shortcut
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\MyDocuments.lnk")
objLink.TargetPath = objFldrItem.Path
objLink.WindowStyle = 3
objLink.Save

Open in new window

Author

Commented:
Thank you for the kind and useful response.

DavidS

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial