How to create shortcut to Computer on the user'

2020-02-11 09:40发布

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

3条回答
爷、活的狠高调
2楼-- · 2020-02-11 09:50

My Computer CLSID is ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}, so the code should be:

With CreateObject("WScript.Shell")
    With .CreateShortcut(.SpecialFolders("Desktop") & "\My Computer.lnk")
        .TargetPath = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
        .Description = "Open My Computer"
        .Save
    End  With
End  With

Also you can use the following shell commands as .TargetPath value:

shell:AccountPictures
shell:AddNewProgramsFolder
shell:Administrative Tools
shell:AppData
shell:Application Shortcuts
shell:AppsFolder
shell:AppUpdatesFolder
shell:Cache
shell:CD Burning
shell:ChangeRemoveProgramsFolder
shell:Common Administrative Tools
shell:Common AppData
shell:Common Desktop
shell:Common Documents
shell:Common Programs
shell:Common Start Menu
shell:Common Startup
shell:Common Templates
shell:CommonDownloads
shell:CommonMusic
shell:CommonPictures
shell:CommonRingtones
shell:CommonVideo
shell:ConflictFolder
shell:ConnectionsFolder
shell:Contacts
shell:ControlPanelFolder
shell:Cookies
shell:Cookies\Low
shell:CredentialManager
shell:CryptoKeys
shell:CSCFolder
shell:Default Gadgets
shell:Desktop
shell:Device Metadata Store
shell:DocumentsLibrary
shell:Downloads
shell:DpapiKeys
shell:Favorites
shell:Fonts
shell:Gadgets
shell:Games
shell:GameTasks
shell:History
shell:HomeGroupCurrentUserFolder
shell:HomeGroupFolder
shell:ImplicitAppShortcuts
shell:InternetFolder
shell:Libraries
shell:Links
shell:Local AppData
shell:LocalAppDataLow
shell:LocalizedResourcesDir
shell:MAPIFolder
shell:MusicLibrary
shell:My Music
shell:My Pictures
shell:My Pictures 
shell:My Video
shell:MyComputerFolder
shell:NetHood
shell:NetworkPlacesFolder
shell:OEM Links 
shell:Original Images
shell:Personal
shell:PhotoAlbums
shell:PicturesLibrary
shell:Playlists
shell:PrintersFolder
shell:PrintHood
shell:Profile
shell:ProgramFiles
shell:ProgramFilesCommon
shell:ProgramFilesCommonX64
shell:ProgramFilesCommonX86
shell:ProgramFilesX64
shell:ProgramFilesX86
shell:Programs
shell:Public
shell:PublicAccountPictures
shell:PublicGameTasks
shell:PublicLibraries
shell:Quick Launch
shell:Recent
shell:RecordedTVLibrary
shell:RecycleBinFolder
shell:ResourceDir
shell:Ringtones
shell:Roamed Tile Images
shell:Roaming Tiles
shell:SampleMusic
shell:SamplePictures
shell:SampleVideos
shell:SavedGames
shell:Screenshots
shell:Searches
shell:SearchHomeFolder
shell:SendTo
shell:Start Menu
shell:Startup
shell:SyncCenterFolder
shell:SyncResultsFolder
shell:SyncSetupFolder
shell:System
shell:SystemCertificates
shell:SystemX86
shell:Templates
shell:User Pinned
shell:UserProfiles
shell:UserProgramFiles
shell:UserProgramFilesCommon
shell:UsersFilesFolder
shell:UsersLibrariesFolder
shell:VideosLibrary
shell:Windows
shell:::{00C6D95F-329C-409A-81D7-C46C66EA7F33} - Default Location
shell:::{00F2886F-CD64-4FC9-8EC5-30EF6CDBE8C3} - Scanners and Cameras
shell:::{0142E4D0-FB7A-11DC-BA4A-000FFE7AB428} - Biometric Devices
shell:::{025A5937-A6BE-4686-A844-36FE4BEC8B6D} - Power Options
shell:::{031E4825-7B94-4DC3-B131-E946B44C8DD5} - Libraries
shell:::{05D7B0F4-2121-4EFF-BF6B-ED3F69B894D9} - Notification Area Icons
shell:::{05D7B0F4-2121-4EFF-BF6B-ED3F69B894D9}\SystemIcons - System Icons
shell:::{0907616E-F5E6-48D8-9D61-A91C3D28106D} - Hyper-V Remote File Browsing
shell:::{0BBCA823-E77D-419E-9A44-5ADEC2C8EEB0} - NVIDIA Control Panel (if installed)
shell:::{0DF44EAA-FF21-4412-828E-260A8728E7F1} - Taskbar and Start Menu
shell:::{1206F5F1-0569-412C-8FEC-3204630DFB70} - Credential Manager
shell:::{15EAE92E-F17A-4431-9F28-805E482DAFD4} - Get Programs
shell:::{17CD9488-1228-4B2F-88CE-4298E93E0966} - Default Programs
shell:::{1CF1260C-4DD0-4EBB-811F-33C572699FDE} - Music folder
shell:::{1D2680C9-0E2A-469D-B787-065558BC7D43} - Fusion Cache
shell:::{1F3427C8-5C10-4210-AA03-2EE45287D668} - User Pinned
shell:::{1FA9085F-25A2-489B-85D4-86326EEDCD87} - Manage Wireless networks
shell:::{208D2C60-3AEA-1069-A2D7-08002B30309D} - Network
shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D} - Computer
shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{374DE290-123F-4565-9164-39C4925E467B} - Downloads folder
shell:::{21EC2020-3AEA-1069-A2DD-08002B30309D} - All Control Panel Items
shell:::{2227A280-3AEA-1069-A2DE-08002B30309D} - Printers
shell:::{22877A6D-37A1-461A-91B0-DBDA5AAEBC99} - Recent Places
shell:::{241D7C96-F8BF-4F85-B01F-E2B043341A4B} - Remote Desktop Connection
shell:::{2559A1F0-21D7-11D4-BDAF-00C04F60B9F0} - Search
shell:::{2559A1F1-21D7-11D4-BDAF-00C04F60B9F0} - Windows Help and Support
shell:::{2559A1F3-21D7-11D4-BDAF-00C04F60B9F0} - Run
shell:::{2559A1F5-21D7-11D4-BDAF-00C04F60B9F0} - E-mail (default program)
shell:::{2559A1F7-21D7-11D4-BDAF-00C04F60B9F0} - Set Program access and Windows defaults
shell:::{2559A1F8-21D7-11D4-BDAF-00C04F60B9F0} - Search Apps
shell:::{26EE0668-A00A-44D7-9371-BEB064C98683} - Control Panel (Category)
shell:::{28803F59-3A75-4058-995F-4EE5503B023C} - Bluetooth Devices
shell:::{289AF617-1CC3-42A6-926C-E6A863F0E3BA} - Media Servers
shell:::{2965E715-EB66-4719-B53F-1672673BBEFA} - Results Folder
shell:::{2E9E59C0-B437-4981-A647-9C34B9B90891} - Sync Setup Folder
shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257} - Desktop
shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257} - Win+Tab
shell:::{323CA680-C24D-4099-B94D-446DD2D7249E} - Favorites
shell:::{35786D3C-B075-49B9-88DD-029876E11C01} - Portable Devices
shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8} - Windows Update
shell:::{37EFD44D-EF8D-41B1-940D-96973A50E9E0} - Desktop Gadgets
shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B} - Network Connections in Notification area
shell:::{3ADD1653-EB32-4CB0-BBD7-DFA0ABB5ACCA} - Pictures folder
shell:::{3F6BC534-DFA1-4AB4-AE54-EF25A74E0107} - System Restore
shell:::{4026492F-2F69-46B8-B9BF-5654FC07E423} - Windows Firewall
shell:::{40419485-C444-4567-851A-2DD7BFA1684D} - Phone and Modem
shell:::{4234D49B-0245-4DF3-B780-3893943456E1} - Applications
shell:::{4336A54D-038B-4685-AB02-99BB52D3FB8B} - Public
shell:::{437FF9C0-A07F-4FA0-AF80-84B6C6440A16} - Command Folder
shell:::{450D8FBA-AD25-11D0-98A8-0800361B1103} - My Documents
shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0} - Control Panel 
shell:::{58E3C745-D971-4081-9034-86E34B30836A} - Speech Recognition
shell:::{59031A47-3F72-44A7-89C5-5595FE6B30EE} - User Folder
shell:::{5EA4F148-308C-46D7-98A9-49041B1DD468} - Windows Mobility Center
shell:::{60632754-C523-4B62-B45C-4172DA012619} - User Accounts
shell:::{62D8ED13-C9D0-4CE8-A914-47DD628FB1B0} - Region and Language
shell:::{645FF040-5081-101B-9F08-00AA002F954E} - Recycle Bin
shell:::{67718415-C450-4F3C-BF8A-B487642DC39B} - Windows Features
shell:::{6785BFAC-9D2D-4BE5-B7E2-59937E8FB80A} - HomeGroup folder
shell:::{67CA7650-96E6-4FDD-BB43-A8E774F73A57} - HomeGroup
shell:::{6C8EEC18-8D75-41B2-A177-8831D59D2D50} - Mouse Properties
shell:::{6DFD7C5C-2451-11D3-A299-00C04F8EF6AF} - Folder Options
shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E} - Network Connections
shell:::{725BE8F7-668E-4C7B-8F90-46BDB0936430} - Keyboard Properties
shell:::{74246BFC-4C96-11D0-ABEF-0020AF6B0B7A} - Device Manager
shell:::{78F3955E-3B90-4184-BD14-5397C15F1EFC} - Performance Information and Tools (WEI)
shell:::{7A9D77BD-5403-11D2-8785-2E0420524153} - Advanced User Accounts (netplwiz)
shell:::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5} - Programs and Features
shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} - Tablet PC Settings
shell:::{85BBD920-42AO-1069-A2E4-08002B30309D} - Briefcase
shell:::{863AA9FD-42DF-457B-8E4D-0DE1B8015C60} - Printers
shell:::{871C5380-42A0-1069-A2EA-08002B30309D} - Internet Explorer
shell:::{87D66A43-7B11-4A28-9811-C86EE395ACF7} - Indexing Options
shell:::{8E0C279D-0BD1-43C3-9EBD-31C3DC5B8A77} - Windows To Go
shell:::{8E74D236-7F35-4720-B138-1FED0B85EA75} - SkyDrive folder (Windows 8.1)
shell:::{8E908FC9-BECC-40F6-915B-F4CA0E70D03D} - Network and Sharing Center
shell:::{93412589-74D4-4E4E-AD0E-E0CB621440FD} - Font settings
shell:::{9343812E-1C37-4A49-A12E-4B2D810D956B} - Search Results
shell:::{96AE8D84-A250-4520-95A5-A47A7E3C548B} - Parental Controls
shell:::{992CFFA0-F557-101A-88EC-00DD010CCC48} - Network Connections
shell:::{9C60DE1E-E5FC-40F4-A487-460851A8D915} - AutoPlay
shell:::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF} - Sync Center
shell:::{9FE63AFD-59CF-4419-9775-ABCC3849F861} - Recovery
shell:::{A0275511-0E86-4ECA-97C2-ECD8F1221D08} - Infared
shell:::{A0953C92-50DC-43BF-BE83-3742FED03C9C} - Videos folder
shell:::{A304259D-52B8-4526-8B1A-A1D6CECC8243} - iSCSI Initiator Properties
shell:::{A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE} - Internet Properties
shell:::{A6482830-08EB-41E2-84C1-73920C2BADB9} - Removable Storage Devices
shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A} - Devices and Printers
shell:::{A8CDFF1C-4878-43BE-B5FD-F8091C1C60D0} - Documents folder
shell:::{AFDB1F70-2A4C-11D2-9039-00C04F8EEB3E} - Offline Files Folder
shell:::{B155BDF8-02F0-451E-9A26-AE317CFD7779} - delegate folder that appears in Computer
shell:::{B2C761C6-29BC-4F19-9251-E6195265BAF1} - Color Management
shell:::{B4BFCC3A-DB2C-424C-B029-7FE99A87C641} - Desktop folder
shell:::{B4FB3F98-C1EA-428D-A78A-D1F5659CBA93} - HomeGroup
shell:::{B98A2BEA-7D42-4558-8BD1-832F41BAC6FD} - Windows 7 File Recovery
shell:::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE} - System
shell:::{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6} - Action Center
shell:::{BD84B380-8CA2-1069-AB1D-08000948534} - Fonts
shell:::{BE122A0E-4503-11DA-8BDE-F66BAD1E3F3A} - Add Features
shell:::{BF782CC9-5A52-4A17-806C-2A894FFEEAC5} - Language Settings
shell:::{C555438B-3C23-4769-A71F-B6D3D9B6053A} - Display (size of text)
shell:::{C58C4893-3BE0-4B45-ABB5-A63E4B8C8651} - Troubleshooting
shell:::{D17D1D6D-CC3F-4815-8FE3-607E7D5D10B3} - Text to Speech
shell:::{D20EA4E1-3957-11D2-A40B-0C5020524153} - Administrative Tools
shell:::{D24F75AA-4F2B-4D07-A3C4-469B3D9030C4} - Offline Files
shell:::{D34A6CA6-62C2-4C34-8A7C-14709C1AD938} - Common Places FS Folder
shell:::{D4480A50-BA28-11D1-8E75-00C04FA31A86} - Add Network Location
shell:::{D450A8A1-9568-45C7-9C0E-B4F9FB4537BD} - Installed Updates
shell:::{D555645E-D4F8-4C29-A827-D93C859C4F2A} - Ease of Access Center
shell:::{D8559EB9-20C0-410E-BEDA-7ED416AECC2A} - Windows Defender
shell:::{D9EF8727-CAC2-4E60-809E-86F80A666C91} - BitLocker Drive Encryption
shell:::{E2E7934B-DCE5-43C4-9576-7FE4F75E7480} - Date and Time
shell:::{E44E5D18-0652-4508-A4E2-8A090067BCB0} - Default Programs
shell:::{E95A4861-D57A-4BE1-AD0F-35267E261739} - Windows SideShow (Windows 8 only)
shell:::{E9950154-C418-419E-A90A-20C5287AE24B} - Location and Other Sensors
shell:::{ECDB0924-4208-451E-8EE0-373C0956DE16} - Work Folders (Windows 8.1)
shell:::{ED228FDF-9EA8-4870-83B1-96B02CFE0D52} - Games
shell:::{ED50FC29-B964-48A9-AFB3-15EBB9B97F36} - printhood delegate folder
shell:::{ED7BA470-8E54-465E-825C-99712043E01C} - All Tasks
shell:::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921} - Personalization
shell:::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C} - Network
shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D} - Sound
shell:::{F6B6E965-E9B2-444B-9286-10C9152EDBC5} - File History
shell:::{F82DF8F7-8B9F-442E-A48C-818EA735FF9B} - Pen and Touch
shell:::{F8C2AB3B-17BC-41DA-9758-339D7DBF2D88} - Previous Versions Results Folder
shell:::{F90C627B-7280-45DB-BC26-CCE7BDD620A4} - Control Panel (All Settings)
shell:::{F942C606-0914-47AB-BE56-1321B8035096} - Storage Spaces

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 \ShortcutTestfolder on the desktop, also folder objects are created, then report is saved and opened as .htm file.

Const e = "<font color=red>Error<font>"
On Error Resume Next
aCLSIDs = Array("shell:AccountPictures", "shell:AddNewProgramsFolder", "shell:Administrative Tools", "shell:AppData", "shell:Application Shortcuts", "shell:AppsFolder", "shell:AppUpdatesFolder", "shell:Cache", "shell:CD Burning", "shell:ChangeRemoveProgramsFolder", "shell:Common Administrative Tools", "shell:Common AppData", "shell:Common Desktop", "shell:Common Documents", "shell:Common Programs", "shell:Common Start Menu", "shell:Common Startup", "shell:Common Templates", "shell:CommonDownloads", "shell:CommonMusic", "shell:CommonPictures", "shell:CommonRingtones", "shell:CommonVideo", "shell:ConflictFolder", "shell:ConnectionsFolder", "shell:Contacts", "shell:ControlPanelFolder", "shell:Cookies", "shell:Cookies\Low", "shell:CredentialManager", "shell:CryptoKeys", "shell:CSCFolder", "shell:Default Gadgets", "shell:Desktop", "shell:Device Metadata Store", "shell:DocumentsLibrary", "shell:Downloads", "shell:DpapiKeys", "shell:Favorites", "shell:Fonts", "shell:Gadgets", "shell:Games", "shell:GameTasks", "shell:History", "shell:HomeGroupCurrentUserFolder", "shell:HomeGroupFolder", "shell:ImplicitAppShortcuts", "shell:InternetFolder", "shell:Libraries", "shell:Links", "shell:Local AppData", "shell:LocalAppDataLow", "shell:LocalizedResourcesDir", "shell:MAPIFolder", "shell:MusicLibrary", "shell:My Music", "shell:My Pictures", "shell:My Pictures ", "shell:My Video", "shell:MyComputerFolder", "shell:NetHood", "shell:NetworkPlacesFolder", "shell:OEM Links ", "shell:Original Images", "shell:Personal", "shell:PhotoAlbums", "shell:PicturesLibrary", "shell:Playlists", "shell:PrintersFolder", "shell:PrintHood", "shell:Profile", "shell:ProgramFiles", "shell:ProgramFilesCommon", "shell:ProgramFilesCommonX64", "shell:ProgramFilesCommonX86", "shell:ProgramFilesX64", "shell:ProgramFilesX86", "shell:Programs", "shell:Public", "shell:PublicAccountPictures", "shell:PublicGameTasks", "shell:PublicLibraries", "shell:Quick Launch", "shell:Recent", "shell:RecordedTVLibrary", "shell:RecycleBinFolder", "shell:ResourceDir", "shell:Ringtones", "shell:Roamed Tile Images", "shell:Roaming Tiles", "shell:SampleMusic", "shell:SamplePictures", "shell:SampleVideos", "shell:SavedGames", "shell:Screenshots", "shell:Searches", "shell:SearchHomeFolder", "shell:SendTo", "shell:Start Menu", "shell:Startup", "shell:SyncCenterFolder", "shell:SyncResultsFolder", "shell:SyncSetupFolder", "shell:System", "shell:SystemCertificates", "shell:SystemX86", "shell:Templates", "shell:User Pinned", "shell:UserProfiles", "shell:UserProgramFiles", "shell:UserProgramFilesCommon", "shell:UsersFilesFolder", "shell:UsersLibrariesFolder", "shell:VideosLibrary", "shell:Windows", "shell:::{00C6D95F-329C-409A-81D7-C46C66EA7F33} - Default Location", "shell:::{00F2886F-CD64-4FC9-8EC5-30EF6CDBE8C3} - Scanners and Cameras", "shell:::{0142E4D0-FB7A-11DC-BA4A-000FFE7AB428} - Biometric Devices", "shell:::{025A5937-A6BE-4686-A844-36FE4BEC8B6D} - Power Options", "shell:::{031E4825-7B94-4DC3-B131-E946B44C8DD5} - Libraries", "shell:::{05D7B0F4-2121-4EFF-BF6B-ED3F69B894D9} - Notification Area Icons", "shell:::{05D7B0F4-2121-4EFF-BF6B-ED3F69B894D9}\SystemIcons - System Icons", "shell:::{0907616E-F5E6-48D8-9D61-A91C3D28106D} - Hyper-V Remote File Browsing", "shell:::{0BBCA823-E77D-419E-9A44-5ADEC2C8EEB0} - NVIDIA Control Panel (if installed)", "shell:::{0DF44EAA-FF21-4412-828E-260A8728E7F1} - Taskbar and Start Menu", "shell:::{1206F5F1-0569-412C-8FEC-3204630DFB70} - Credential Manager", "shell:::{15EAE92E-F17A-4431-9F28-805E482DAFD4} - Get Programs", "shell:::{17CD9488-1228-4B2F-88CE-4298E93E0966} - Default Programs", "shell:::{1CF1260C-4DD0-4EBB-811F-33C572699FDE} - Music folder", "shell:::{1D2680C9-0E2A-469D-B787-065558BC7D43} - Fusion Cache", "shell:::{1F3427C8-5C10-4210-AA03-2EE45287D668} - User Pinned", "shell:::{1FA9085F-25A2-489B-85D4-86326EEDCD87} - Manage Wireless networks", "shell:::{208D2C60-3AEA-1069-A2D7-08002B30309D} - Network", "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D} - Computer", "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{374DE290-123F-4565-9164-39C4925E467B} - Downloads folder", "shell:::{21EC2020-3AEA-1069-A2DD-08002B30309D} - All Control Panel Items", "shell:::{2227A280-3AEA-1069-A2DE-08002B30309D} - Printers", "shell:::{22877A6D-37A1-461A-91B0-DBDA5AAEBC99} - Recent Places", "shell:::{241D7C96-F8BF-4F85-B01F-E2B043341A4B} - Remote Desktop Connection", "shell:::{2559A1F0-21D7-11D4-BDAF-00C04F60B9F0} - Search", "shell:::{2559A1F1-21D7-11D4-BDAF-00C04F60B9F0} - Windows Help and Support", "shell:::{2559A1F3-21D7-11D4-BDAF-00C04F60B9F0} - Run", "shell:::{2559A1F5-21D7-11D4-BDAF-00C04F60B9F0} - E-mail (default program)", "shell:::{2559A1F7-21D7-11D4-BDAF-00C04F60B9F0} - Set Program access and Windows defaults", "shell:::{2559A1F8-21D7-11D4-BDAF-00C04F60B9F0} - Search Apps", "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683} - Control Panel (Category)", "shell:::{28803F59-3A75-4058-995F-4EE5503B023C} - Bluetooth Devices", "shell:::{289AF617-1CC3-42A6-926C-E6A863F0E3BA} - Media Servers", "shell:::{2965E715-EB66-4719-B53F-1672673BBEFA} - Results Folder", "shell:::{2E9E59C0-B437-4981-A647-9C34B9B90891} - Sync Setup Folder", "shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257} - Desktop", "shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257} - Win+Tab", "shell:::{323CA680-C24D-4099-B94D-446DD2D7249E} - Favorites", "shell:::{35786D3C-B075-49B9-88DD-029876E11C01} - Portable Devices", "shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8} - Windows Update", "shell:::{37EFD44D-EF8D-41B1-940D-96973A50E9E0} - Desktop Gadgets", "shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B} - Network Connections in Notification area", "shell:::{3ADD1653-EB32-4CB0-BBD7-DFA0ABB5ACCA} - Pictures folder", "shell:::{3F6BC534-DFA1-4AB4-AE54-EF25A74E0107} - System Restore", "shell:::{4026492F-2F69-46B8-B9BF-5654FC07E423} - Windows Firewall", "shell:::{40419485-C444-4567-851A-2DD7BFA1684D} - Phone and Modem", "shell:::{4234D49B-0245-4DF3-B780-3893943456E1} - Applications", "shell:::{4336A54D-038B-4685-AB02-99BB52D3FB8B} - Public", "shell:::{437FF9C0-A07F-4FA0-AF80-84B6C6440A16} - Command Folder", "shell:::{450D8FBA-AD25-11D0-98A8-0800361B1103} - My Documents", "shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0} - Control Panel ", "shell:::{58E3C745-D971-4081-9034-86E34B30836A} - Speech Recognition", "shell:::{59031A47-3F72-44A7-89C5-5595FE6B30EE} - User Folder", "shell:::{5EA4F148-308C-46D7-98A9-49041B1DD468} - Windows Mobility Center", "shell:::{60632754-C523-4B62-B45C-4172DA012619} - User Accounts", "shell:::{62D8ED13-C9D0-4CE8-A914-47DD628FB1B0} - Region and Language", "shell:::{645FF040-5081-101B-9F08-00AA002F954E} - Recycle Bin", "shell:::{67718415-C450-4F3C-BF8A-B487642DC39B} - Windows Features", "shell:::{6785BFAC-9D2D-4BE5-B7E2-59937E8FB80A} - HomeGroup folder", "shell:::{67CA7650-96E6-4FDD-BB43-A8E774F73A57} - HomeGroup", "shell:::{6C8EEC18-8D75-41B2-A177-8831D59D2D50} - Mouse Properties", "shell:::{6DFD7C5C-2451-11D3-A299-00C04F8EF6AF} - Folder Options", "shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E} - Network Connections", "shell:::{725BE8F7-668E-4C7B-8F90-46BDB0936430} - Keyboard Properties", "shell:::{74246BFC-4C96-11D0-ABEF-0020AF6B0B7A} - Device Manager", "shell:::{78F3955E-3B90-4184-BD14-5397C15F1EFC} - Performance Information and Tools (WEI)", "shell:::{7A9D77BD-5403-11D2-8785-2E0420524153} - Advanced User Accounts (netplwiz)", "shell:::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5} - Programs and Features", "shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} - Tablet PC Settings", "shell:::{85BBD920-42AO-1069-A2E4-08002B30309D} - Briefcase", "shell:::{863AA9FD-42DF-457B-8E4D-0DE1B8015C60} - Printers", "shell:::{871C5380-42A0-1069-A2EA-08002B30309D} - Internet Explorer", "shell:::{87D66A43-7B11-4A28-9811-C86EE395ACF7} - Indexing Options", "shell:::{8E0C279D-0BD1-43C3-9EBD-31C3DC5B8A77} - Windows To Go", "shell:::{8E74D236-7F35-4720-B138-1FED0B85EA75} - SkyDrive folder (Windows 8.1)", "shell:::{8E908FC9-BECC-40F6-915B-F4CA0E70D03D} - Network and Sharing Center", "shell:::{93412589-74D4-4E4E-AD0E-E0CB621440FD} - Font settings", "shell:::{9343812E-1C37-4A49-A12E-4B2D810D956B} - Search Results", "shell:::{96AE8D84-A250-4520-95A5-A47A7E3C548B} - Parental Controls", "shell:::{992CFFA0-F557-101A-88EC-00DD010CCC48} - Network Connections", "shell:::{9C60DE1E-E5FC-40F4-A487-460851A8D915} - AutoPlay", "shell:::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF} - Sync Center", "shell:::{9FE63AFD-59CF-4419-9775-ABCC3849F861} - Recovery", "shell:::{A0275511-0E86-4ECA-97C2-ECD8F1221D08} - Infared", "shell:::{A0953C92-50DC-43BF-BE83-3742FED03C9C} - Videos folder", "shell:::{A304259D-52B8-4526-8B1A-A1D6CECC8243} - iSCSI Initiator Properties", "shell:::{A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE} - Internet Properties", "shell:::{A6482830-08EB-41E2-84C1-73920C2BADB9} - Removable Storage Devices", "shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A} - Devices and Printers", "shell:::{A8CDFF1C-4878-43BE-B5FD-F8091C1C60D0} - Documents folder", "shell:::{AFDB1F70-2A4C-11D2-9039-00C04F8EEB3E} - Offline Files Folder", "shell:::{B155BDF8-02F0-451E-9A26-AE317CFD7779} - delegate folder that appears in Computer", "shell:::{B2C761C6-29BC-4F19-9251-E6195265BAF1} - Color Management", "shell:::{B4BFCC3A-DB2C-424C-B029-7FE99A87C641} - Desktop folder", "shell:::{B4FB3F98-C1EA-428D-A78A-D1F5659CBA93} - HomeGroup", "shell:::{B98A2BEA-7D42-4558-8BD1-832F41BAC6FD} - Windows 7 File Recovery", "shell:::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE} - System", "shell:::{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6} - Action Center", "shell:::{BD84B380-8CA2-1069-AB1D-08000948534} - Fonts", "shell:::{BE122A0E-4503-11DA-8BDE-F66BAD1E3F3A} - Add Features", "shell:::{BF782CC9-5A52-4A17-806C-2A894FFEEAC5} - Language Settings", "shell:::{C555438B-3C23-4769-A71F-B6D3D9B6053A} - Display (size of text)", "shell:::{C58C4893-3BE0-4B45-ABB5-A63E4B8C8651} - Troubleshooting", "shell:::{D17D1D6D-CC3F-4815-8FE3-607E7D5D10B3} - Text to Speech", "shell:::{D20EA4E1-3957-11D2-A40B-0C5020524153} - Administrative Tools", "shell:::{D24F75AA-4F2B-4D07-A3C4-469B3D9030C4} - Offline Files", "shell:::{D34A6CA6-62C2-4C34-8A7C-14709C1AD938} - Common Places FS Folder", "shell:::{D4480A50-BA28-11D1-8E75-00C04FA31A86} - Add Network Location", "shell:::{D450A8A1-9568-45C7-9C0E-B4F9FB4537BD} - Installed Updates", "shell:::{D555645E-D4F8-4C29-A827-D93C859C4F2A} - Ease of Access Center", "shell:::{D8559EB9-20C0-410E-BEDA-7ED416AECC2A} - Windows Defender", "shell:::{D9EF8727-CAC2-4E60-809E-86F80A666C91} - BitLocker Drive Encryption", "shell:::{E2E7934B-DCE5-43C4-9576-7FE4F75E7480} - Date and Time", "shell:::{E44E5D18-0652-4508-A4E2-8A090067BCB0} - Default Programs", "shell:::{E95A4861-D57A-4BE1-AD0F-35267E261739} - Windows SideShow (Windows 8 only)", "shell:::{E9950154-C418-419E-A90A-20C5287AE24B} - Location and Other Sensors", "shell:::{ECDB0924-4208-451E-8EE0-373C0956DE16} - Work Folders (Windows 8.1)", "shell:::{ED228FDF-9EA8-4870-83B1-96B02CFE0D52} - Games", "shell:::{ED50FC29-B964-48A9-AFB3-15EBB9B97F36} - printhood delegate folder", "shell:::{ED7BA470-8E54-465E-825C-99712043E01C} - All Tasks", "shell:::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921} - Personalization", "shell:::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C} - Network", "shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D} - Sound", "shell:::{F6B6E965-E9B2-444B-9286-10C9152EDBC5} - File History", "shell:::{F82DF8F7-8B9F-442E-A48C-818EA735FF9B} - Pen and Touch", "shell:::{F8C2AB3B-17BC-41DA-9758-339D7DBF2D88} - Previous Versions Results Folder", "shell:::{F90C627B-7280-45DB-BC26-CCE7BDD620A4} - Control Panel (All Settings)", "shell:::{F942C606-0914-47AB-BE56-1321B8035096} - Storage Spaces")
Set oWSHShell = CreateObject("WScript.Shell")
Set oShellApp = CreateObject("Shell.Application")
sUserPc = oWSHShell.ExpandEnvironmentStrings("%username%@%computername%")
sReportPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, ".") - 1) & "_" & sUserPc & ".htm"
sShTestPath = oWSHShell.SpecialFolders("Desktop") & "\ShortcutTest\"
SmartCreateFolder sShTestPath
s = "<html><head><title>Test some CLSID for Shell</title><style>* {font-family: consolas, courier new; font-size: 8pt;} h1 {font-size: 14pt;} table {border-collapse: collapse; background: transparent;} td, th {border: black 1px solid; vertical-align: top; padding: 2px 5px;} th {background: lightgrey;}</style></head><body>" & sUserPc & " " & Now & "<h1>Test some CLSID for Shell</h1>"
s = s & "<p><font color=limegreen>' VBScript example of saving .lnk shortcut and creating folder object</font><br>&nbsp;<br>sCLSID = <font color=crimson>""shell:::{031E4825-7B94-4dc3-B131-E946B44C8DD5}""</font> <font color=limegreen>' CLSID</font><br>&nbsp;<br><font color=limegreen>' WScript.Shell Shortcut</font><br><font color=darkviolet>Set</font> oWSHShell = <font color=darkorange>CreateObject</font>(<font color=crimson>""WScript.Shell""</font>)<br><font color=darkviolet>With</font> oWSHShell.CreateShortcut(<font color=crimson>""C:\Libraries.lnk""</font>)<br>&nbsp; &nbsp; .TargetPath = sCLSID<br>&nbsp; &nbsp; .Save<br>&nbsp; &nbsp; sShTargetPath = .TargetPath <font color=limegreen>' Actual Shortcut TargetPath</font><br><font color=darkviolet>End</font> <font color=darkviolet>With</font><br>&nbsp;<br><font color=limegreen>' Shell.Application Folder</font><br><font color=darkviolet>Set</font> oShellApp = <font color=darkorange>CreateObject</font>(<font color=crimson>""Shell.Application""</font>)<br><font color=darkviolet>Set</font> oFolder = oShellApp.NameSpace(sCLSID)<br>sNameSpace = <font color=darkorange>TypeName</font>(oFolder) <font color=limegreen>' Shell NameSpace Typename</font><br>sFolderPath = oFolder.Self.Path <font color=limegreen>' Shell Folder Path</font><br>sFolderTitle = oFolder.Title <font color=limegreen>' Shell Folder Title</font><br></p>"
s = s & "<table><tr><th>n</th><th>CLSID</th><th>Shell NameSpace Typename</th><th>Shell Folder Title</th><th>Shell Folder Path</th><th>Shortcut TargetPath</th></tr>"
For n = 0 To UBound(aCLSIDs)
    sCLSID = aCLSIDs(n)
    ' Shell.Application
    Set oFolder = oShellApp.NameSpace(sCLSID)
    If Err Then
        Err.Clear
        sNameSpace = e
        sFolderPath = e
        sFolderTitle = e
        sShName = "[NameSpace Error]"
    Else
        sNameSpace = TypeName(oFolder)
        If sNameSpace = "Nothing" Then
            sNameSpace = "<font color=red>Nothing<font>"
            sFolderPath = e
            sFolderTitle = e
            sShName = "[Folder Error]"
        Else
            sFolderPath = oFolder.Self.Path
            If Err Then
                Err.Clear
                sFolderPath = e
            End If
            sFolderTitle = oFolder.Title
            If Err Then
                Err.Clear
                sFolderTitle = e
                sShName = "[Title Error]"
            Else
                sShName = sFolderTitle
            End If
        End If
    End If
    ' WScript.Shell
    With oWSHShell.CreateShortcut(sShTestPath & n & " " & sShName & ".lnk")
        .TargetPath = sCLSID
        .Save
        sShTargetPath = .TargetPath
    End  With
    If Err Then
        Err.Clear
        sShTargetPath = e
    End If
    ' results
    s = s & "<tr><td>" & n & "</td><td>" & sCLSID & "</td><td>" & sNameSpace & "</td><td>" & sFolderTitle & "</td><td>" & sFolderPath & "</td><td>" & sShTargetPath & "</td></tr>"
Next
s = s & "</table></body></html>"
WriteTextFile s, sReportPath, -1
oWSHShell.Run sReportPath

Sub SmartCreateFolder(sFolder)
    ' http://www.visualbasicscript.com/tm.aspx?m=29290
    With CreateObject("Scripting.FileSystemObject")
        If Not .FolderExists(sFolder) then
            SmartCreateFolder .getparentfoldername(sFolder)
            .CreateFolder sFolder
        End If
    End With 
End Sub

Sub WriteTextFile(sContent, sPath, lFormat)
    ' lFormat -2 - System default, -1 - Unicode, 0 - ASCII
    With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 2, True, lFormat)
        .Write sContent
        .Close
    End With
End Sub
查看更多
Juvenile、少年°
3楼-- · 2020-02-11 09:55

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. hex dump of shortcut to computer 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.

查看更多
地球回转人心会变
4楼-- · 2020-02-11 09:57

This should do the trick :

Option Explicit
Const MY_COMPUTER = &H11
Dim ws, Desktop, Link, ObjF, ObjFItem, Shell
Set ws = CreateObject("Wscript.Shell")
Set Shell = CreateObject("Shell.Application")
Set ObjF = Shell.Namespace(MY_COMPUTER)
Desktop = ws.SpecialFolders("Desktop")
Set Link = ws.CreateShortcut(Desktop & "\My Computer.lnk")
Set ObjFItem = ObjF.Self
Link.TargetPath = ObjFItem.Path
Link.WindowStyle = 1
Link.IconLocation = "Shell32.dll, 15"
Link.Description = "Shortcut To My Computer"
Link.WorkingDirectory = Desktop
Link.Save
查看更多
登录 后发表回答