Create a shortcut for the current vbscript or any other application with arguments using an array


Option Explicit
Const Title = "Create a shortcut for the current vbscript or any other application with arguments using an array"
Call RunAsAdmin()

Create_Shortcut Array("Desktop","Windows Defender Settings","ms-settings:windowsdefender")

Create_Shortcut Array("Desktop","Recent","shell:Recent")

Create_Shortcut Array("Desktop","User profile","%userprofile%")

Create_Shortcut Array(_
    "Desktop",_
    "NetworkDiagnostics",_
    "%SystemRoot%\system32\msdt.exe",_
    "-skip TRUE -path %Windir%\diagnostics\system\networking -ep NetworkDiagnosticsPNI",_
    "%SystemRoot%\system32\msdt.exe,0",_
    "Network Diagnostics to fix connections problems",_
    "CTRL+ALT+D"_
)
'-------------------------------------------------------------------------------------------------------
Sub Create_Shortcut(rArgs) 
    Dim objShell,objShortCut,ObjShortcutPath,ShortcutName,ShortcutPath,ShortcutLocation
    Dim TargetPath,Arguments,IconLocation,Description,HotKey
    Set objShell = CreateObject("WScript.Shell")
    If UBound(rArgs) > 1 Then
        ShortcutLocation       = cstr(rArgs(0))
        ShortcutPath           = objShell.SpecialFolders(ShortcutLocation)
        ShortcutName           = cstr(rArgs(1))
        Set objShortCut        = objShell.CreateShortcut(ShortcutPath & "\" & ShortcutName & ".lnk")
        TargetPath             = objShell.ExpandEnvironmentStrings(rArgs(2))
        objShortCut.TargetPath = TargetPath 
        If ShortcutPath = "" Then 
            MsgBox "Error The Shortcut Path Does Not Exsists On Your System."_
            ,vbCritical+vbSystemModal,Title
            wscript.quit(1)
        End If
    End If

    If UBound(rArgs) > 2 Then
        Arguments = cstr(rArgs(3))
        objShortCut.Arguments = Arguments
    End If

    If UBound(rArgs) > 3 Then
        IconLocation = cstr(rArgs(4))
        ObjShortCut.IconLocation = IconLocation
    End If

    If UBound(rArgs) > 4 Then
        Description = cstr(rArgs(5))
        ObjShortCut.Description = Description
    End If

    If UBound(rArgs) > 5 Then
        HotKey = cstr(rArgs(6))
        ObjShortCut.HotKey = HotKey
    End If
    objShortCut.Save
    On Error Resume Next
    If Err.Number <> 0 Then
        ShowError() 
    Else 
        objShell.Popup "The Shortcut "& chr(34) & ShortcutName & chr(34) &" is created Successfully !"& vbcrlf &_
        "On " & chr(34) & ShortcutPath & chr(34),5,Title,vbInformation+vbSystemModal
    End If
End Sub
'-------------------------------------------------------------------------------------------------------
Sub ShowError()
    ErrDetail = "Description : " & Err.Description & vbCrlf & _
    "Error number : " & Err.Number & vbCrlf & _
    "Error source : " & Err.Source
    MsgBox ErrDetail,vbCritical+vbSystemModal,Title
    Err.clear
End Sub
'-------------------------------------------------------------------------------------------------------
Sub RunAsAdmin()
    If Not WScript.Arguments.Named.Exists("elevate") Then
        CreateObject("Shell.Application").ShellExecute WScript.FullName _
        , chr(34) & WScript.ScriptFullName & chr(34) & " /elevate", "", "runas", 1
        WScript.Quit
    End If
End Sub
'-------------------------------------------------------------------------------------------------------
REM 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}", "shell:::{00F2886F-CD64-4FC9-8EC5-30EF6CDBE8C3}", "shell:::{0142E4D0-FB7A-11DC-BA4A-000FFE7AB428}", "shell:::{025A5937-A6BE-4686-A844-36FE4BEC8B6D}", "shell:::{031E4825-7B94-4DC3-B131-E946B44C8DD5}", "shell:::{05D7B0F4-2121-4EFF-BF6B-ED3F69B894D9}", "shell:::{05D7B0F4-2121-4EFF-BF6B-ED3F69B894D9}\SystemIcons - System Icons", "shell:::{0907616E-F5E6-48D8-9D61-A91C3D28106D}", "shell:::{0BBCA823-E77D-419E-9A44-5ADEC2C8EEB0}", "shell:::{0DF44EAA-FF21-4412-828E-260A8728E7F1}", "shell:::{1206F5F1-0569-412C-8FEC-3204630DFB70}", "shell:::{15EAE92E-F17A-4431-9F28-805E482DAFD4}", "shell:::{17CD9488-1228-4B2F-88CE-4298E93E0966}", "shell:::{1CF1260C-4DD0-4EBB-811F-33C572699FDE}", "shell:::{1D2680C9-0E2A-469D-B787-065558BC7D43}", "shell:::{1F3427C8-5C10-4210-AA03-2EE45287D668}", "shell:::{1FA9085F-25A2-489B-85D4-86326EEDCD87}", "shell:::{208D2C60-3AEA-1069-A2D7-08002B30309D}", "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{374DE290-123F-4565-9164-39C4925E467B}", "shell:::{21EC2020-3AEA-1069-A2DD-08002B30309D}", "shell:::{2227A280-3AEA-1069-A2DE-08002B30309D}", "shell:::{22877A6D-37A1-461A-91B0-DBDA5AAEBC99}", "shell:::{241D7C96-F8BF-4F85-B01F-E2B043341A4B}", "shell:::{2559A1F0-21D7-11D4-BDAF-00C04F60B9F0}", "shell:::{2559A1F1-21D7-11D4-BDAF-00C04F60B9F0}", "shell:::{2559A1F3-21D7-11D4-BDAF-00C04F60B9F0}", "shell:::{2559A1F5-21D7-11D4-BDAF-00C04F60B9F0}", "shell:::{2559A1F7-21D7-11D4-BDAF-00C04F60B9F0}", "shell:::{2559A1F8-21D7-11D4-BDAF-00C04F60B9F0}", "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}", "shell:::{28803F59-3A75-4058-995F-4EE5503B023C}", "shell:::{289AF617-1CC3-42A6-926C-E6A863F0E3BA}", "shell:::{2965E715-EB66-4719-B53F-1672673BBEFA}", "shell:::{2E9E59C0-B437-4981-A647-9C34B9B90891}", "shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}", "shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257}", "shell:::{323CA680-C24D-4099-B94D-446DD2D7249E}", "shell:::{35786D3C-B075-49B9-88DD-029876E11C01}", "shell:::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8}", "shell:::{37EFD44D-EF8D-41B1-940D-96973A50E9E0}", "shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B}", "shell:::{3ADD1653-EB32-4CB0-BBD7-DFA0ABB5ACCA}", "shell:::{3F6BC534-DFA1-4AB4-AE54-EF25A74E0107}", "shell:::{4026492F-2F69-46B8-B9BF-5654FC07E423}", "shell:::{40419485-C444-4567-851A-2DD7BFA1684D}", "shell:::{4234D49B-0245-4DF3-B780-3893943456E1}", "shell:::{4336A54D-038B-4685-AB02-99BB52D3FB8B}", "shell:::{437FF9C0-A07F-4FA0-AF80-84B6C6440A16}", "shell:::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", "shell:::{58E3C745-D971-4081-9034-86E34B30836A}", "shell:::{59031A47-3F72-44A7-89C5-5595FE6B30EE}", "shell:::{5EA4F148-308C-46D7-98A9-49041B1DD468}", "shell:::{60632754-C523-4B62-B45C-4172DA012619}", "shell:::{62D8ED13-C9D0-4CE8-A914-47DD628FB1B0}", "shell:::{645FF040-5081-101B-9F08-00AA002F954E}", "shell:::{67718415-C450-4F3C-BF8A-B487642DC39B}", "shell:::{6785BFAC-9D2D-4BE5-B7E2-59937E8FB80A}", "shell:::{67CA7650-96E6-4FDD-BB43-A8E774F73A57}", "shell:::{6C8EEC18-8D75-41B2-A177-8831D59D2D50}", "shell:::{6DFD7C5C-2451-11D3-A299-00C04F8EF6AF}", "shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E}", "shell:::{725BE8F7-668E-4C7B-8F90-46BDB0936430}", "shell:::{74246BFC-4C96-11D0-ABEF-0020AF6B0B7A}", "shell:::{78F3955E-3B90-4184-BD14-5397C15F1EFC}", "shell:::{7A9D77BD-5403-11D2-8785-2E0420524153}", "shell:::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5}", "shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E}", "shell:::{85BBD920-42AO-1069-A2E4-08002B30309D}", "shell:::{863AA9FD-42DF-457B-8E4D-0DE1B8015C60}", "shell:::{871C5380-42A0-1069-A2EA-08002B30309D}", "shell:::{87D66A43-7B11-4A28-9811-C86EE395ACF7}", "shell:::{8E0C279D-0BD1-43C3-9EBD-31C3DC5B8A77}", "shell:::{8E74D236-7F35-4720-B138-1FED0B85EA75}", "shell:::{8E908FC9-BECC-40F6-915B-F4CA0E70D03D}", "shell:::{93412589-74D4-4E4E-AD0E-E0CB621440FD}", "shell:::{9343812E-1C37-4A49-A12E-4B2D810D956B}", "shell:::{96AE8D84-A250-4520-95A5-A47A7E3C548B}", "shell:::{992CFFA0-F557-101A-88EC-00DD010CCC48}", "shell:::{9C60DE1E-E5FC-40F4-A487-460851A8D915}", "shell:::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}", "shell:::{9FE63AFD-59CF-4419-9775-ABCC3849F861}", "shell:::{A0275511-0E86-4ECA-97C2-ECD8F1221D08}", "shell:::{A0953C92-50DC-43BF-BE83-3742FED03C9C}", "shell:::{A304259D-52B8-4526-8B1A-A1D6CECC8243}", "shell:::{A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE}", "shell:::{A6482830-08EB-41E2-84C1-73920C2BADB9}", "shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}", "shell:::{A8CDFF1C-4878-43BE-B5FD-F8091C1C60D0}", "shell:::{AFDB1F70-2A4C-11D2-9039-00C04F8EEB3E}", "shell:::{B155BDF8-02F0-451E-9A26-AE317CFD7779}", "shell:::{B2C761C6-29BC-4F19-9251-E6195265BAF1}", "shell:::{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}", "shell:::{B4FB3F98-C1EA-428D-A78A-D1F5659CBA93}", "shell:::{B98A2BEA-7D42-4558-8BD1-832F41BAC6FD}", "shell:::{BB06C0E4-D293-4F75-8A90-CB05B6477EEE}", "shell:::{BB64F8A7-BEE7-4E1A-AB8D-7D8273F7FDB6}", "shell:::{BD84B380-8CA2-1069-AB1D-08000948534}", "shell:::{BE122A0E-4503-11DA-8BDE-F66BAD1E3F3A}", "shell:::{BF782CC9-5A52-4A17-806C-2A894FFEEAC5}", "shell:::{C555438B-3C23-4769-A71F-B6D3D9B6053A}", "shell:::{C58C4893-3BE0-4B45-ABB5-A63E4B8C8651}", "shell:::{D17D1D6D-CC3F-4815-8FE3-607E7D5D10B3}", "shell:::{D20EA4E1-3957-11D2-A40B-0C5020524153}", "shell:::{D24F75AA-4F2B-4D07-A3C4-469B3D9030C4}", "shell:::{D34A6CA6-62C2-4C34-8A7C-14709C1AD938}", "shell:::{D4480A50-BA28-11D1-8E75-00C04FA31A86}", "shell:::{D450A8A1-9568-45C7-9C0E-B4F9FB4537BD}", "shell:::{D555645E-D4F8-4C29-A827-D93C859C4F2A}", "shell:::{D8559EB9-20C0-410E-BEDA-7ED416AECC2A}", "shell:::{D9EF8727-CAC2-4E60-809E-86F80A666C91}", "shell:::{E2E7934B-DCE5-43C4-9576-7FE4F75E7480}", "shell:::{E44E5D18-0652-4508-A4E2-8A090067BCB0}", "shell:::{E95A4861-D57A-4BE1-AD0F-35267E261739}", "shell:::{E9950154-C418-419E-A90A-20C5287AE24B}", "shell:::{ECDB0924-4208-451E-8EE0-373C0956DE16}", "shell:::{ED228FDF-9EA8-4870-83B1-96B02CFE0D52}", "shell:::{ED50FC29-B964-48A9-AFB3-15EBB9B97F36}", "shell:::{ED7BA470-8E54-465E-825C-99712043E01C}", "shell:::{ED834ED6-4B5A-4BFE-8F11-A626DCB6A921}", "shell:::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}", "shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D}", "shell:::{F6B6E965-E9B2-444B-9286-10C9152EDBC5}", "shell:::{F82DF8F7-8B9F-442E-A48C-818EA735FF9B}", "shell:::{F8C2AB3B-17BC-41DA-9758-339D7DBF2D88}", "shell:::{F90C627B-7280-45DB-BC26-CCE7BDD620A4}", "shell:::{F942C606-0914-47AB-BE56-1321B8035096}")
'-------------------------------------------------------------------------------------------------------
'About WshShell.SpecialFolders
'Obtain the full path to any of the special Windows folders (Desktop, Start Menu etc).
'Syntax 
'      strMyPath = objShell.SpecialFolders("strFolderName")
'      or
'      strMyPath = objShell.SpecialFolders.Item("strFolderName")
'Arguments:
'   objShell   A WScript.Shell object 
'   strFolderName : One of the following special folders (not all are available to all flavors of Windows)
'      AllUsersDesktop
'      AllUsersStartMenu
'      AllUsersPrograms
'      AllUsersStartup
'      Desktop
'      Favorites
'      Fonts
'      MyDocuments
'      NetHood
'      PrintHood
'      Programs
'      Recent
'      SendTo
'      StartMenu
'      Startup
'      Templates
'Returns:
'strMyPath : The full path to the special folder returns NULL if the folder is not available.
'------------------------------------------------------------------------------------------------------
'explorer windowsdefender://Threat               # Virus & Threat Protection
'explorer windowsdefender://ThreatSettings       # Virus & Threat Protection Settings
'explorer windowsdefender://Account              # Account Protection
'explorer windowsdefender://Network              # Firewall & network Protection
'explorer windowsdefender://Hardware             # Device Security
'explorer windowsdefender://DeviceSecurity       # Device Security
'explorer windowsdefender://Family               # Family Option
'explorer windowsdefender://AppBrowser           # App & Browser Control
'explorer windowsdefender://Settings             # Manage Notifications
'explorer windowsdefender://History              # Protection History
'explorer windowsdefender://RansomwareProtection # Ransomware Protection
'explorer windowsdefender://ProtectedFolders     # Ransomware Protection
'explorer windowsdefender://SecurityProcessor    # Security Processor Details
'explorer windowsdefender://SecurityProcessorTroubleshooting #  Security Processor Troubleshooting
'explorer windowsdefender://SmartScreenPua       # Smart Screen (Reputation Based Protection)
'explorer windowsdefender://AccountProtection    # Account Protection
'explorer windowsdefender://ExploitProtection    # Exploit Protection
'explorer windowsdefender://exclusions           # exclusions
'explorer windowsdefender://fullscan             # Select fullscan
'explorer windowsdefender://quickscan            # Start quickscan 
'------------------------------------------------------------------------------------------------------
Edit
Pub: 05 Oct 2022 05:31 UTC
Views: 161