March 4th, 2013

Marking a shortcut to say that it should not be placed on the Windows 8 Start page upon installation or treated as a newly-installed application

Today’s Little Program creates a shortcut on the Start menu but marks it as “Do not put me on the front page upon installation.” This is something you should do to any secondary shortcuts your installer creates. And while you’re at it, you may as well set the “Don’t highlight me as a newly-installed program” attribute used by Windows 7. (Remember, Little Programs do little to no error checking.)

#define UNICODE
#define _UNICODE
#define STRICT
#include <windows.h>
#include <shlobj.h>
#include <atlbase.h>
#include <propkey.h>
#include <shlwapi.h>

int __cdecl wmain(int, wchar_t **) { CCoInitialize init;

CComPtr<IShellLink> spsl; spsl.CoCreateInstance(CLSID_ShellLink);

wchar_t szSelf[MAX_PATH]; GetModuleFileName(GetModuleHandle(nullptr), szSelf, ARRAYSIZE(szSelf)); spsl->SetPath(szSelf);

PROPVARIANT pvar; CComQIPtr<IPropertyStore> spps(spsl);

pvar.vt = VT_UI4; pvar.ulVal = APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL; spps->SetValue(PKEY_AppUserModel_StartPinOption, pvar);

pvar.vt = VT_BOOL; pvar.boolVal = VARIANT_TRUE; CComQIPtr<IPropertyStore> spps(spsl); spps->SetValue(PKEY_AppUserModel_ExcludeFromShowInNewInstall, pvar);

spps->Commit();

wchar_t szPath[MAX_PATH]; SHGetSpecialFolderPath(nullptr, szPath, CSIDL_PROGRAMS, FALSE); PathAppend(szPath, L”Awesome.lnk”); CComQIPtr<IPersistFile>(spsl)->Save(szPath, FALSE);

return 0; }

First, we create a shell link object.

Next, we tell the shell link that its target is the currently-running program.

Now the fun begins. We get the property store of the shortcut and set two new properties.

We then commit those properties back into the shortcut.

Finally, we save the shortcut.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.