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

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon