Hi all,

I would like to be able to create shortcuts that refer to folders in the =
namespace rather than the file system. For example: if you right-click =
My Documents on the desktop and choose 'create shortcut', then explore =
the shortcut, the folder pane shows the folder as a subfolder of the =
Desktop.

The properties exposed by the shortcut object returned from =
WshShell.CreateShortcut are identical for shortcuts that refer to =
"Desktop\My Documents", "Desktop\My Computer\<user name>'s Documents" =
and "C:\Documents and Settings\<username>\My Documents".

If I use the Shell objects described in the MSDN here:
http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/=
objects/objects.asp

I can distinguish between these by obtaining the Target property =
(returns a FolderItem object) of the ShellLinkObject and recursively =
evaluating the Parent property, but the Target property is read-only :-( =
--- and my goal is to create such a shortcut.

So far, all that works is obtaining the FolderItem for the folder I want =
to create a shortcut to and then using FolderItem.InvokeVerb("Create =
&Shortcut"). The drawback of this are:

1. No control over the name of the shortcut
2. For certain folders (Documents under My Computer for example), the =
"Windows cannot create a shortcut here, would you like to place it on =
the desktop instead?" message appears and needs to be "OK'd" by the user =
before execution continues.
3. Use of "Create &Shortcut" creates language dependence. (I assume -- =
not critical, but it's nice)

My ultimate goal is to be able to open & close a folder without its =
flashing on the screen. I thought if I created shortcuts, I could set =
them to open minimized. I could use Run explorer.exe with CLSIDs for =
everything except the user folders under My Computer, I can't figure out =
a command line to open those.

Anybody have any ideas?

Thanks for your time,
Keith

Re: Can you create a shortcut to a namespace folder? by Walter

Walter
Sun Apr 10 11:50:03 CDT 2005

Try this sub, passing it the full path of the shortcut which you wis to
create and the ID of the namespace object you wish to create a shortcut
to.

' Create a shortcut to My Computer on the c: drive
CreateShortcut("c:\My Computer.lnk",17)

Sub CreateShortcut(ShortcutPath,SpecialFolderConstant)
Dim Shell
Dim Shortcut
Dim ShellApp
Set Shell = CreateObject("WScript.Shell")
Set ShellApp = CreateObject("Shell.Application")
Set Shortcut = Shell.CreateShortcut(ShortcutPath)
Shortcut.TargetPath =
ShellApp.Namespace(SpecialFolderConstant).Self.Path
Shortcut.Save
End Sub

The namespace ID's can be found at
http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/objects/shell/shellspecialfolderconstants.asp