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

DWStovall used Ask the Experts™
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.

   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"
   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"
   objShell.SendKeys "{F5}"

Open in new window

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.


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

   strRegWriteValue = 1
   objShell.RegWrite strRegWriteKey,strRegWriteValue,"REG_DWORD"
   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

Open in new window


Thank you for the kind and useful response.


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