1 diff --git a/src/wintoastlib.cpp b/src/wintoastlib.cpp
2 index 0895ff7..52de554 100644
3 --- a/src/wintoastlib.cpp
4 +++ b/src/wintoastlib.cpp
5 @@ -391,6 +391,10 @@ void WinToast::setAppUserModelId(_In_ const std::wstring& aumi) {
6 DEBUG_MSG(L"Default App User Model Id: " << _aumi.c_str());
9 +void WinToast::setShortcutPolicy(_In_ ShortcutPolicy shortcutPolicy) {
10 + _shortcutPolicy = shortcutPolicy;
13 bool WinToast::isCompatible() {
14 DllImporter::initialize();
15 return !((DllImporter::SetCurrentProcessExplicitAppUserModelID == nullptr)
16 @@ -492,10 +496,12 @@ bool WinToast::initialize(_Out_ WinToastError* error) {
20 - if (createShortcut() < 0) {
21 - setError(error, WinToastError::ShellLinkNotCreated);
22 - DEBUG_MSG(L"Error while attaching the AUMI to the current proccess =(");
24 + if (_shortcutPolicy != SHORTCUT_POLICY_IGNORE) {
25 + if (createShortcut() < 0) {
26 + setError(error, WinToastError::ShellLinkNotCreated);
27 + DEBUG_MSG(L"Error while attaching the AUMI to the current proccess =(");
32 if (FAILED(DllImporter::SetCurrentProcessExplicitAppUserModelID(_aumi.c_str()))) {
33 @@ -555,18 +561,23 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
34 hr = DllImporter::PropVariantToString(appIdPropVar, AUMI, MAX_PATH);
36 if (FAILED(hr) || _aumi != AUMI) {
37 - // AUMI Changed for the same app, let's update the current value! =)
39 - PropVariantClear(&appIdPropVar);
40 - hr = InitPropVariantFromString(_aumi.c_str(), &appIdPropVar);
41 - if (SUCCEEDED(hr)) {
42 - hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar);
43 + if (_shortcutPolicy == SHORTCUT_POLICY_REQUIRE_CREATE) {
44 + // AUMI Changed for the same app, let's update the current value! =)
46 + PropVariantClear(&appIdPropVar);
47 + hr = InitPropVariantFromString(_aumi.c_str(), &appIdPropVar);
49 - hr = propertyStore->Commit();
50 - if (SUCCEEDED(hr) && SUCCEEDED(persistFile->IsDirty())) {
51 - hr = persistFile->Save(path, TRUE);
52 + hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar);
53 + if (SUCCEEDED(hr)) {
54 + hr = propertyStore->Commit();
55 + if (SUCCEEDED(hr) && SUCCEEDED(persistFile->IsDirty())) {
56 + hr = persistFile->Save(path, TRUE);
61 + // Not allowed to touch the shortcut to fix the AUMI
65 PropVariantClear(&appIdPropVar);
66 @@ -581,6 +592,10 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
69 HRESULT WinToast::createShellLinkHelper() {
70 + if (_shortcutPolicy != SHORTCUT_POLICY_REQUIRE_CREATE) {
74 WCHAR exePath[MAX_PATH]{L'\0'};
75 WCHAR slPath[MAX_PATH]{L'\0'};
76 Util::defaultShellLinkPath(_appName, slPath);
77 diff --git a/src/wintoastlib.h b/src/wintoastlib.h
78 index 68b1cb1..dc8d745 100644
79 --- a/src/wintoastlib.h
80 +++ b/src/wintoastlib.h
81 @@ -173,6 +173,16 @@ namespace WinToastLib {
82 SHORTCUT_CREATE_FAILED = -4
85 + enum ShortcutPolicy {
86 + /* Don't check, create, or modify a shortcut. */
87 + SHORTCUT_POLICY_IGNORE = 0,
88 + /* Require a shortcut with matching AUMI, don't create or modify an existing one. */
89 + SHORTCUT_POLICY_REQUIRE_NO_CREATE = 1,
90 + /* Require a shortcut with matching AUMI, create if missing, modify if not matching.
91 + * This is the default. */
92 + SHORTCUT_POLICY_REQUIRE_CREATE = 2,
97 static WinToast* instance();
98 @@ -194,10 +204,12 @@ namespace WinToastLib {
99 const std::wstring& appUserModelId() const;
100 void setAppUserModelId(_In_ const std::wstring& aumi);
101 void setAppName(_In_ const std::wstring& appName);
102 + void setShortcutPolicy(_In_ ShortcutPolicy policy);
105 bool _isInitialized{false};
106 bool _hasCoInitialized{false};
107 + ShortcutPolicy _shortcutPolicy{SHORTCUT_POLICY_REQUIRE_CREATE};
108 std::wstring _appName{};
109 std::wstring _aumi{};
110 std::map<INT64, ComPtr<IToastNotification>> _buffer{};