I am working on a VBScript that is to show the "Computer" icon on the desktop. I've been able to do one for IE using the following code, however as Computer is a "Special Folder" that does not seem to have an actual location I can't use the same method. Would anyone have any idea how to enable it via VBScript?
IE Shortcut code:
Set objShell = WScript.CreateObject("WScript.Shell")
'Create Shortcut for IE on desktop
allUsersDesktop = objShell.SpecialFolders("AllUsersDesktop")
usersDesktop = objShell.SpecialFolders("Desktop")
Set objShortCut = objShell.CreateShortcut(usersDesktop & "\Internet Explorer.lnk")
objShortCut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe"
objShortCut.Description = "Open Internet Explorer"
objShortCut.Save
My Computer CLSID is
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
, so the code should be:Also you can use the following shell commands as
.TargetPath
value:E. g.
.TargetPath = "shell:::{1FA9085F-25A2-489B-85D4-86326EEDCD87}"
Note, you can just enter that shell commands in explorer window as path to test them.
UPDATE
The below VBScript code helps to test some CLSIDS: shortcuts are created in
\ShortcutTest
folder on the desktop, also folder objects are created, then report is saved and opened as.htm
file.TL;DR
While this is not the standard method of creating shortcuts, in this case, it might be your best option.
Create a shortcut to "Computer" interactively with the GUI shell. To deploy the shortcut: copy that file with the script.
Explanation
Windows shortcuts (.lnk) are among a myriad of undocumented features of Windows. Though I cannot find any description of the file format, it's not terribly complicated. The fields that you can set when you create/edit them interactively are present in the file (in UCS-16LE or some similar encoding).
Normally, you can see what windows uses for the target of a shortcut when you edit the shortcut. When you look at one of the special shortcuts, Windows will hide the CLSID (or whatever it actually is)—a well-known GUID that refers to something Windows Special™. In the case of "Computer," that identifier is
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
, and I suspect (!!) that it doesn't change at all when moving from computer to computer.Here's the hex dump of a shortcut I just created. I don't see any references to anything install-specific.
If the shortcut depended on environment variables or other computer-specific details, then just copying the .lnk file would be a terrible idea. However, because doing it The Right Way™ isn't easy, copying the .lnk file should be easy and (reasonably) robust.
This should do the trick :