blob: 612ac322d760a1b40ca1b3e23e8bcac52eb2e3be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include "stdafx.h"
#define SHORTCUT_PATH "\\Microsoft\\Windows\\Start Menu\\Programs\\Miranda NG.lnk"
using namespace Microsoft::WRL;
wchar_t* GetShortcutPath()
{
wchar_t path[MAX_PATH];
GetEnvironmentVariable(_T("APPDATA"), path, MAX_PATH);
wcscat_s(path, _T(SHORTCUT_PATH));
return mir_wstrdup(path);
}
HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath)
{
wchar_t exePath[MAX_PATH];
GetModuleFileName(NULL, exePath, MAX_PATH);
ComPtr<IShellLink> shellLink;
CHECKHR(CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)));
CHECKHR(shellLink->SetPath(exePath));
CHECKHR(shellLink->SetArguments(L""));
ComPtr<IPropertyStore> propertyStore;
CHECKHR(shellLink.As(&propertyStore));
PROPVARIANT appIdPropVar;
HRESULT hr = InitPropVariantFromString(AppUserModelID, &appIdPropVar);
if (SUCCEEDED(hr))
{
CHECKHR(propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar));
CHECKHR(propertyStore->Commit());
ComPtr<IPersistFile> persistFile;
CHECKHR(hr = shellLink.As(&persistFile))
hr = persistFile->Save(shortcutPath, TRUE);
}
PropVariantClear(&appIdPropVar);
return hr;
}
bool ShortcutExists()
{
return (GetFileAttributes(ptrW(GetShortcutPath())) < 0xFFFFFFF);
}
HRESULT TryCreateShortcut()
{
return (ShortcutExists() ? S_OK : InstallShortcut(ptrW(GetShortcutPath())));
}
|