VBS to modify a start menu recent app shortcut

Home Forums Scripting General Scripting VBS to modify a start menu recent app shortcut

This topic contains 2 replies, has 3 voices, and was last updated by Avatar Adalberto 5 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    KodiaK
    Member
    #163137

    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.

    Rems
    Rems
    Moderator
    #228407

    Re: VBS to modify a start menu recent app shortcut

    The ‘recent programs list’ is kept in subkeys under this registry key HKEY_CURRENT_USERSoftwareMicrosoft WindowsCurrentVersionExplorerUserAssist

    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%RoamingMicrosoftInternet ExplorerQuick LaunchUser PinnedStartMenu”
    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,

    Code:
    ‘ it could take a couple of seconds before the changes are visible

    Const HKCU = &H80000001

    ‘ Display name of the shortcut
    TXTa = “[B]AppShortcut v1[/B].lnk” ‘ the .lnk extension is added on purpose

    regKey = “SoftwareMicrosoftWindowsCurrentVersionExplorerUserAssist”
    Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\.rootdefault: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
    Next
    Next

    wscript.quit

    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 cd = cd-26
    ElseIf cd >= 97 and cd = 122 then cd = cd-26
    End If
    coded = coded & chr(cd )
    Next
    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”.

    Code:
    ‘ [URL=”http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx”]Pin Items to the Start Menu via Script[/URL]
    ‘ It is better to pin the Start Menu shortcuts for items instead of directly pinning the executable.

    Const CSIDL_COMMON_PROGRAMS = &H17
    Const CSIDL_PROGRAMS = &H2

    strProgramSubFolders = “[B]my application[/B]”
    strProgramShortcut = “[B]AppShortcut v2[/B].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(objVerb.name, “&”, “”) = “Pin to Start Menu” Then objVerb.DoIt
    Next

    You can merge the two to one script.

    /Rems

    Avatar
    Adalberto
    Member
    #386774

    Re: VBS to modify a start menu recent app shortcut

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

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.