mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 14:36:15 -05:00
fix(windows): register the notification shortcut identity
This commit is contained in:
3 files changed
+64
-1
No files matched your search
@@ -59,6 +59,11 @@ from the Start menu after completion. User configuration and licensing state
|
|||||||
are retained during upgrades and uninstall. Authenticode setup is separate;
|
are retained during upgrades and uninstall. Authenticode setup is separate;
|
||||||
WinSparkle must still verify the installer payload signature before handoff.
|
WinSparkle must still verify the installer payload signature before handoff.
|
||||||
|
|
||||||
|
The Start menu shortcut registers `System.AppUserModel.ID` as `com.yuezk.gpgui`,
|
||||||
|
matching the GUI and native toast sender. Windows uses the shortcut's name and
|
||||||
|
executable icon to identify GP Connect in Notification Center. Its identity is
|
||||||
|
part of the shortcut, so the existing shortcut rollback and uninstall own its cleanup.
|
||||||
|
|
||||||
Manual launches show an Install/Cancel confirmation page (Update/Cancel when
|
Manual launches show an Install/Cancel confirmation page (Update/Cancel when
|
||||||
GP Connect is already installed). The update feed supplies `/UPDATE` through
|
GP Connect is already installed). The update feed supplies `/UPDATE` through
|
||||||
WinSparkle's `sparkle:installerArguments` to skip that page after the user has
|
WinSparkle's `sparkle:installerArguments` to skip that page after the user has
|
||||||
|
|||||||
@@ -144,6 +144,58 @@ function Set-MachineState {
|
|||||||
} finally { $registry.Dispose() }
|
} 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) {
|
function Set-InstallationMetadata([string]$InstalledVersion) {
|
||||||
$shell = New-Object -ComObject WScript.Shell
|
$shell = New-Object -ComObject WScript.Shell
|
||||||
$shortcut = $shell.CreateShortcut($shortcutPath)
|
$shortcut = $shell.CreateShortcut($shortcutPath)
|
||||||
@@ -152,6 +204,7 @@ function Set-InstallationMetadata([string]$InstalledVersion) {
|
|||||||
$shortcut.Description = 'A GUI client for GlobalProtect VPN'
|
$shortcut.Description = 'A GUI client for GlobalProtect VPN'
|
||||||
$shortcut.IconLocation = (Join-Path $destination 'gpgui.exe') + ',0'
|
$shortcut.IconLocation = (Join-Path $destination 'gpgui.exe') + ',0'
|
||||||
$shortcut.Save()
|
$shortcut.Save()
|
||||||
|
Set-ShortcutAppUserModelId $shortcutPath 'com.yuezk.gpgui'
|
||||||
if (Test-Path -LiteralPath (Join-Path $destination 'uninstall.exe')) {
|
if (Test-Path -LiteralPath (Join-Path $destination 'uninstall.exe')) {
|
||||||
New-Item -Path $uninstallKey -Force | Out-Null
|
New-Item -Path $uninstallKey -Force | Out-Null
|
||||||
$values = @{
|
$values = @{
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ $service = Get-CimInstance Win32_Service -Filter "Name='GPConnect'"
|
|||||||
if ($service.State -ne 'Running' -or $service.StartMode -ne 'Auto' -or $service.StartName -ne 'LocalSystem') {
|
if ($service.State -ne 'Running' -or $service.StartMode -ne 'Auto' -or $service.StartName -ne 'LocalSystem') {
|
||||||
throw 'The service did not start automatically as LocalSystem.'
|
throw 'The service did not start automatically as LocalSystem.'
|
||||||
}
|
}
|
||||||
|
$shortcut = Join-Path $env:ProgramData 'Microsoft\Windows\Start Menu\Programs\GP Connect.lnk'
|
||||||
|
$shell = New-Object -ComObject Shell.Application
|
||||||
|
$link = $shell.Namespace((Split-Path $shortcut)).ParseName((Split-Path $shortcut -Leaf))
|
||||||
|
if (!$link -or $link.ExtendedProperty('System.AppUserModel.ID') -ne 'com.yuezk.gpgui') {
|
||||||
|
throw 'The Start menu shortcut does not register the notification application identity.'
|
||||||
|
}
|
||||||
foreach ($name in @('gpgui.exe', 'gpauth.exe')) {
|
foreach ($name in @('gpgui.exe', 'gpauth.exe')) {
|
||||||
$process = Start-Process (Join-Path $destination $name) -ArgumentList '--version' -PassThru -Wait
|
$process = Start-Process (Join-Path $destination $name) -ArgumentList '--version' -PassThru -Wait
|
||||||
if ($process.ExitCode -ne 0) { throw "The installed $name cannot start." }
|
if ($process.ExitCode -ne 0) { throw "The installed $name cannot start." }
|
||||||
@@ -44,7 +50,6 @@ if ($process.ExitCode -ne 0) { throw 'The uninstaller failed.' }
|
|||||||
if ((Get-Service GPConnect -ErrorAction SilentlyContinue) -or (Test-Path $destination) -or (Test-Path ($destination + '.previous'))) {
|
if ((Get-Service GPConnect -ErrorAction SilentlyContinue) -or (Test-Path $destination) -or (Test-Path ($destination + '.previous'))) {
|
||||||
throw 'The uninstaller left service registration or runtime files.'
|
throw 'The uninstaller left service registration or runtime files.'
|
||||||
}
|
}
|
||||||
$shortcut = Join-Path $env:ProgramData 'Microsoft\Windows\Start Menu\Programs\GP Connect.lnk'
|
|
||||||
if ((Test-Path $shortcut) -or (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GPConnect')) {
|
if ((Test-Path $shortcut) -or (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GPConnect')) {
|
||||||
throw 'The uninstaller left its shortcut or registration.'
|
throw 'The uninstaller left its shortcut or registration.'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user