Codester.NET

The blog for Windows system admins…

Pinning Applications to the Start Menu for All Users in Windows 7

I recently had a requirement to pin an application the Start Menu for All Users of the new corporate desktop during the Windows 7 automated build process.

 

Creating a shortcut in the All Users start menu is easily achieved by copying the shortcut to the folder C:\ProgramData\Microsoft\Windows\Start Menu\.  Pinning the application to the Start Menu is easy from within Windows; simply right click on the application shortcut and hit ‘Pin to Start Menu’.  However, achieving the same results automatically for all users is not so straight forward!

 

Icons manually pinned to the Start Menu are stored in the folder:

%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu

There are also registry settings stored that hold this pinned application configuration (but as they as binary values it’s pretty much impossible to de-couple the settings).

 

Using Group Policy Preferences it is possible to add apps to the Start Menu.  However it is not possible to pin the apps so this is a dead end.

 

After some further investigation I uncovered the following information on the Microsoft website:

 

According to MS:

There is no direct programmatic interface to add pinned items to either the Start Menu or Windows 7 Taskbar.  This was done deliberately to prevent installation programs from spamming these locations with their icons (http://blogs.msdn.com/oldnewthing/archive/2003/09/03/54760.aspx).  This caused many customers to have to take manual steps in the image build process to configure pinned items.  However, there is an indirect way to automate this by using the Shell Objects for Scripting.

 

Some further research revealed the following VBscript which will pin the MyApp shortcut located in the C:\ProgramData\Microsoft\Windows\Start Menu\ programs folder to the Start Menu using Shell Objects.

 

Set objShell = CreateObject(“Shell.Application”)

Set objFolder = objShell.Namespace(“C:\ProgramData\Microsoft\Windows\Start Menu\programs”)

Set objFolderItem = objFolder.ParseName(“MyApp.lnk”)

Set colVerbs = objFolderItem.Verbs

For Each objVerb in colVerbs

If Replace(objVerb.name, “&”, “”) = “Pin to Start Menu” Then objVerb.DoIt

Next

 

So now that I can automate the process of pinning the app to the Start Menu I just need a way of achieving this for all users.  The solution is to use Active Setup.

 

Active Setup is used to configure user based settings for an application by running once per user.  During the early stage of the logon the registry keys under:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components

Are compared to those under:

HKEY_CURRENT_USER\Software\Microsoft\Active Setup\Installed Components

 

Where an entry exists under HKEY_LOCAL_MACHINE\ but not under HKEY_CURRENT_USER\ Windows knows it has not run this Active Setup component.  It will look for the ‘Stubpath’ value under the key and execute the command referenced.  It will then add the key name under the HKEY_CURRENT_USER\ portion of the registry so that it will not run again for the current user.

 

So by copying the VBscript created earlier (PinMyApp.vbs) to C:\source\ and importing the following registry (PinMyApp.reg) file to the PC we have implemented a solution.

 

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\pinmyapp]

@=”Pin My App to Start Menu”

“StubPath”=”c:\\source\\PinMyApp.vbs”

 

Note that the double back slash is required in a reg file.

 

In this case the key name under Installed Components is called pinmyapp.  Typically, application GUIDs are used here but it’s not essential to do so.  If your application doesn’t already have a GUID associated with it you can generate one using an online GUID generator (just Google it).

 

I simply wrapped up these two actions into a batch file as follows and copied the reg and vbs files to the same folder as the batch file:

Copy %~dp0PinMyApp.vbs c:\source

Regedit /s %~dp0PinMyApp.reg

 

The batch file is then set to execute as part of the build process (in my case simply added to the MDT task sequence).

 

We have now achieved our goal.  Every user that logs onto the PC will now execute the script that pins the icon and the script will only run once per user.

Category: Uncategorized

Your email address will not be published. Required fields are marked *

*