No announcement yet.

VBS to modify a start menu recent app shortcut

  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS to modify a start menu recent app shortcut

    Hello all,

    Does anybody know of a way to modify a recently opened program shortcut from Start Menu? I prefer a method through a vbs script.
    The situation is as follows: I have an application which has a shortcut AppShortcut v1. Now when the user runs this shortcut, Windows creates a shortcut directly in Start Menu for ease of access for that application.
    The problem is that when that application updates, the shortcut also modifies to AppShortcut v2. But in Start Menu, the recently opened program shortcut is still called AppShortcut v1.
    I have no idea where these kinds of shortcuts are stored, and i don't know how to modify that shortcut so it points to the updated Application Shortcut.

    The OS is Windows Server 2008 R2.

    I know that a easy and quick way is to go to Start Menu/Programs and launch the updated shortcut, but it seems that the users are too lazy to do this, so i have to find a way to modify the recently used programs shortcut.

    Thank you in advance.
    Last edited by KodiaK; 31st January 2014, 20:10.

  • #2
    Re: VBS to modify a start menu recent app shortcut

    The 'recent programs list' is kept in subkeys under this registry key HKEY_CURRENT_USER\Software\Microsoft\ Windows\CurrentVersion\Explorer\UserAssist\

    The entries in the registry are encoded but not difficult to decode. I managed removing a recent program from the list by deleting the entry from the key. (never further tested it thoroughly though).
    But adding a program shortcut to the key could be more complicated, you have to understand how it works which I do not.
    I also tried renaming an existing entry in the hope the name of the link in the list would change too but that didn't work.

    What you could do,
    1st, remove AppShortcut v1 from the Recent Programs List with the script.
    2nd, Instead of looking for a way to add AppShortcut v2 to the Recent Programs List you can add an existing shortcut to the program as a pinned program to the user's start menu with the script.

    Once added as pinned program you can manage the existing pinned items here "%AppData%\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
    You cannot add or delete shortcuts to or from that folder as this will not make any changes in the Start menu. But you can rename and change target of existing shortcuts in that folder manually or with a script.

    remove one program from the recent programs list,
    ' it could take a couple of seconds before the changes are visible
    Const HKCU = &H80000001
    ' Display name of the shortcut
    TXTa = "AppShortcut v1.lnk"  ' the .lnk extension is added on purpose
    regKey = "Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist"
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    ROT13a = encodedecode(TXTa)
    oReg.EnumKey HKCU, regKey, aSub
    For Each sKey In aSub
       oReg.EnumValues HKCU, regKey & "\" & sKey & "\Count", arrValueNames, arrValueTypes
       For V=0 To UBound(arrValueNames)
         If instr(1,arrValueNames(V), ROT13a,1) > 0 Then 
    ' check       WScript.Echo "Value Name: " & encodedecode(arrValueNames(V)) & vbnewline & "Coded Name: " & arrValueNames(V)
           oReg.DeleteValue HKCU, regKey & "\" & sKey & "\Count",arrValueNames(V)
         End If
    function encodedecode(s)
       ' ROT13 ("ROTate by 13 places") is a simple Caesar cipher
       ' used for obscuring text by replacing each letter with the
       ' letter thirteen places down the alphabet. 
       ' ROT13 scrambles only letters.
       For i = 1 To Len(s)  
         cd = Asc(Mid(s, i, 1))
         If  cd >= 65 and cd =< 90 then 'uppercase
           cd = cd+13
           If  cd > 90 then cd = cd-26
         ElseIf  cd >= 97 and cd =< 122 then 'lowercase
           cd = cd+13
           If  cd > 122 then cd = cd-26
         End If
         coded = coded & chr(cd )
       encodedecode = coded  
    End Function
    pin an existing shortcut from the Start / All Programs menu to the Start menu.
    Note that this script works for an English version of Windows 7. You might have to
    translate the verb "Pin to Start Menu".
    ' Pin Items to the Start Menu via Script
    ' It is better to pin the Start Menu shortcuts for items instead of directly pinning the executable.
    Const CSIDL_PROGRAMS = &H2
    strProgramSubFolders = "\my application"
    strProgramShortcut = "AppShortcut v2.lnk"  ' the .lnk extension should be added
    Set objShell = CreateObject("Shell.Application")
    Set objProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) ' or CSIDL_PROGRAMS
    strProgramsPath = objProgramsFolder.Self.Path
    Set objFolder = objShell.Namespace(strProgramsPath & strProgramSubFolders)
    Set objFolderItem = objFolder.ParseName(strProgramShortcut)
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
        If Replace(, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
    You can merge the two to one script.


    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts


    • #3
      Re: VBS to modify a start menu recent app shortcut

      Thank a lot Rems.
      It works under Windows Server 2008 R2 too.