fix(windows): register the notification shortcut identity

This commit is contained in:
Kevin Yue committed 2026-11-18 18:18:07 +08:00
1 parent 8b0d1af648
commit afd5ec3f09
3 files changed
+64 -1

No files matched your search

+53
View File
@@ -144,6 +144,58 @@ function Set-MachineState {
} finally { $registry.Dispose() }
}
function Set-ShortcutAppUserModelId([string]$Path, [string]$ApplicationId) {
if (-not ('GPConnect.Installer.ShortcutIdentity' -as [type])) {
Add-Type @'
using System;
using System.Runtime.InteropServices;
namespace GPConnect.Installer {
public static class ShortcutIdentity {
[StructLayout(LayoutKind.Sequential)]
private struct PropertyKey { public Guid Format; public uint Id; }
// PROPVARIANT is 24 bytes in both supported 64-bit architectures.
[StructLayout(LayoutKind.Explicit, Size = 24)]
private struct PropVariant {
[FieldOffset(0)] public ushort Type;
[FieldOffset(8)] public IntPtr Value;
}
[ComImport, Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IPropertyStore {
void GetCount(out uint count);
void GetAt(uint index, out PropertyKey key);
void GetValue(ref PropertyKey key, out PropVariant value);
void SetValue(ref PropertyKey key, ref PropVariant value);
void Commit();
}
[DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
private static extern void SHGetPropertyStoreFromParsingName(
string path, IntPtr context, uint flags, ref Guid iid, out IPropertyStore store);
public static void Set(string path, string applicationId) {
var iid = typeof(IPropertyStore).GUID;
IPropertyStore store;
SHGetPropertyStoreFromParsingName(path, IntPtr.Zero, 2, ref iid, out store); // GPS_READWRITE
var value = new PropVariant { Type = 31, Value = Marshal.StringToCoTaskMemUni(applicationId) }; // VT_LPWSTR
try {
var key = new PropertyKey { Format = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), Id = 5 };
store.SetValue(ref key, ref value); // PKEY_AppUserModel_ID
store.Commit();
} finally {
Marshal.FreeCoTaskMem(value.Value);
Marshal.ReleaseComObject(store);
}
}
}
}
'@
}
[GPConnect.Installer.ShortcutIdentity]::Set($Path, $ApplicationId)
}
function Set-InstallationMetadata([string]$InstalledVersion) {
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
@@ -152,6 +204,7 @@ function Set-InstallationMetadata([string]$InstalledVersion) {
$shortcut.Description = 'A GUI client for GlobalProtect VPN'
$shortcut.IconLocation = (Join-Path $destination 'gpgui.exe') + ',0'
$shortcut.Save()
Set-ShortcutAppUserModelId $shortcutPath 'com.yuezk.gpgui'
if (Test-Path -LiteralPath (Join-Path $destination 'uninstall.exe')) {
New-Item -Path $uninstallKey -Force | Out-Null
$values = @{