locked
VB Script to Unpin Programs from Start Menu RRS feed

  • Question

  • I am trying to unpin calculator and XPS Viewer from the Start Menu in Windows 7 using a VB Script.  This is the script I am using but it does not work:

    Const CSIDL_COMMON_PROGRAMS = &H17
    Const CSIDL_PROGRAMS = &H2
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
    Set objFolderItem = objFolder.ParseName("Calculator.lnk")
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
        If Replace(objVerb.name, "&", "") = "&Delete" Then objVerb.DoIt
    Next

     

    Please help!

    Wednesday, July 27, 2011 4:19 PM

Answers

  • Hi,

    Your question is about "Remove from this list", which is not the same as "Unpin from Start Menu". The script you posted depends on the Shell object (Shell.Application) to access a FolderItem object's verbs. When I tested on my Windows 7 machine, "Remove from this list" is not one of the available verbs. You can test this with the following JScript script (.js file):

    // listItemVerbs.js
    var ERROR_FILE_NOT_FOUND = 2;
    
    function main() {
     var args = WScript.Arguments;
    
     if ((args.Unnamed.length == 0) || (args.Named.Exists("?"))) {
      WScript.Echo("Usage: listItemVerbs.js <filename>");
      return 0;
     }
    
     var fileFullPath = args.Unnamed.Item(0);
    
     var fso = new ActiveXObject("Scripting.FileSystemObject");
     if (! fso.FileExists(fileFullPath)) {
      WScript.Echo("File not found - " + fileFullPath);
      return ERROR_FILE_NOT_FOUND;
     }
     var filePath = fso.GetParentFolderName(fileFullPath);
     var fileName = fso.GetFileName(fileFullPath);
    
     var shApp = new ActiveXObject("Shell.Application");
     var folder = shApp.NameSpace(filePath);
     var folderItem = folder.ParseName(fileName);
    
     var output = "Name: " + folderItem.Name + "\r\n" +
      "Verb list:";
     var verbs = new Enumerator(folderItem.Verbs());
     for (; ! verbs.atEnd(); verbs.moveNext()) {
      output += "\r\n\t" + verbs.item().Name;
     }
     WScript.Echo(output);
    }
    
    WScript.Quit(main());
    

    Run this script with a command-line argument of the full path to a program that has the "Remove from this list" item on the Start menu. When I run this command on my machine:

    cscript listItemVerbs.js "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

    I get this output:

    Name: powershell.exe
    Verb list:
        &Open
        Run as &administrator
    
        Scan for threats...
        Pin to Tas&kbar
        Pin to Start Men&u
        Restore previous &versions
    
        Cu&t
        &Copy
        Create &shortcut
        &Delete
        Rena&me
        P&roperties
    

    On my machine, there is no "Remove from this list" verb.

    That said, there might be a way to do this, but "Remove from this list" appears not to be available from the Shell.Application object.

    HTH,

    Bill

    • Proposed as answer by Bill_Stewart Thursday, July 28, 2011 8:21 PM
    • Marked as answer by IamMred Monday, August 1, 2011 4:09 AM
    Wednesday, July 27, 2011 9:18 PM

All replies

  • Hi,

    Are these items actually pinned to the top of the Start menu (e.g., when you right-click, is there an "Unpin from Start Menu" option)?

    Bill

    Wednesday, July 27, 2011 4:31 PM
  • Hi,

    You could see if you can port the technique used in this PowerShell to suit your needs.


    Jan Egil Ring

    Blog: http://blog.powershell.no
    Twitter: http://twitter.com/janegilring
    Wednesday, July 27, 2011 5:00 PM
  • I am trying to apply these settings on top of our WIM as I want to make the image as thin as possible.  Our deployment tool (similar to MDT) cannot execute power shell scripts, only executables, vb scripts, or batch files.  These items are at the bottom and only have the option to remove from the list, not unpin. 
    Wednesday, July 27, 2011 5:13 PM
  • Hi,

    It sounds like what you are seeing is Windows displaying a sample list of programs on the Start menu the first time the user opens the Start menu (i.e., to give them a sample of some preinstalled applications they can run). This list is updated dynamically by Windows and is determined by usage.

    This blog entry applies to XP, but the underlying purpose is the same: http://blogs.msdn.com/b/oldnewthing/archive/2007/06/18/3369797.aspx

    I am wondering why you want a completely empty Start menu?

    Bill

    Wednesday, July 27, 2011 5:23 PM
  • I am not attempting to empty the entire start menu, just clean it up a little by deleting programs that are pinned that my users will not utilize.
    Wednesday, July 27, 2011 6:48 PM
  • Hi,

    Your question is about "Remove from this list", which is not the same as "Unpin from Start Menu". The script you posted depends on the Shell object (Shell.Application) to access a FolderItem object's verbs. When I tested on my Windows 7 machine, "Remove from this list" is not one of the available verbs. You can test this with the following JScript script (.js file):

    // listItemVerbs.js
    var ERROR_FILE_NOT_FOUND = 2;
    
    function main() {
     var args = WScript.Arguments;
    
     if ((args.Unnamed.length == 0) || (args.Named.Exists("?"))) {
      WScript.Echo("Usage: listItemVerbs.js <filename>");
      return 0;
     }
    
     var fileFullPath = args.Unnamed.Item(0);
    
     var fso = new ActiveXObject("Scripting.FileSystemObject");
     if (! fso.FileExists(fileFullPath)) {
      WScript.Echo("File not found - " + fileFullPath);
      return ERROR_FILE_NOT_FOUND;
     }
     var filePath = fso.GetParentFolderName(fileFullPath);
     var fileName = fso.GetFileName(fileFullPath);
    
     var shApp = new ActiveXObject("Shell.Application");
     var folder = shApp.NameSpace(filePath);
     var folderItem = folder.ParseName(fileName);
    
     var output = "Name: " + folderItem.Name + "\r\n" +
      "Verb list:";
     var verbs = new Enumerator(folderItem.Verbs());
     for (; ! verbs.atEnd(); verbs.moveNext()) {
      output += "\r\n\t" + verbs.item().Name;
     }
     WScript.Echo(output);
    }
    
    WScript.Quit(main());
    

    Run this script with a command-line argument of the full path to a program that has the "Remove from this list" item on the Start menu. When I run this command on my machine:

    cscript listItemVerbs.js "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

    I get this output:

    Name: powershell.exe
    Verb list:
        &Open
        Run as &administrator
    
        Scan for threats...
        Pin to Tas&kbar
        Pin to Start Men&u
        Restore previous &versions
    
        Cu&t
        &Copy
        Create &shortcut
        &Delete
        Rena&me
        P&roperties
    

    On my machine, there is no "Remove from this list" verb.

    That said, there might be a way to do this, but "Remove from this list" appears not to be available from the Shell.Application object.

    HTH,

    Bill

    • Proposed as answer by Bill_Stewart Thursday, July 28, 2011 8:21 PM
    • Marked as answer by IamMred Monday, August 1, 2011 4:09 AM
    Wednesday, July 27, 2011 9:18 PM
  • Thanks for your help. 
    Thursday, July 28, 2011 5:34 PM
  • FYI

    InvokeVerb "startpin"

    InvokeVerb "startunpin"

    Monday, December 24, 2012 5:40 AM