From bf00bcd2a4fee0855567b62cff83a0006c7c3232 Mon Sep 17 00:00:00 2001 From: Owen Dunn Date: Mon, 29 Aug 2016 16:55:42 +0100 Subject: [PATCH] SetCurrentProcessExplicitAppUserModelID to fix jumplist/removable media bug The algorithm Windows uses to generate AppUserModelIDs "hangs on" to removable media (CDs/DVDs) if PuTTY is launched with a CD/DVD in a drive. Set the AppUserModelID explicitly to avoid using this algorithm. --- windows/window.c | 5 +++++ windows/winjump.c | 30 ++++++++++++++++++++++++++++++ windows/winstuff.h | 1 + 3 files changed, 36 insertions(+) diff --git a/windows/window.c b/windows/window.c index 11546410..044d3ce3 100644 --- a/windows/window.c +++ b/windows/window.c @@ -357,6 +357,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) InitCommonControls(); + /* Set Explicit App User Model Id so that jump lists don't cause + PuTTY to hang on to removable media. */ + + set_explicit_app_user_model_id(); + /* Ensure a Maximize setting in Explorer doesn't maximise the * config box. */ defuse_showwindow(); diff --git a/windows/winjump.c b/windows/winjump.c index e5bca935..85963a32 100644 --- a/windows/winjump.c +++ b/windows/winjump.c @@ -714,3 +714,33 @@ void remove_session_from_jumplist(const char * const sessionname) clear_jumplist(); } } + +/* Set Explicit App User Model Id to fix removable media error with + jump lists */ + +BOOL set_explicit_app_user_model_id() +{ + DECL_WINDOWS_FUNCTION(static, HRESULT, SetCurrentProcessExplicitAppUserModelID, + (PCWSTR)); + + static HMODULE shell32_module = 0; + + if (!shell32_module) + { + shell32_module = load_system32_dll("Shell32.dll"); + GET_WINDOWS_FUNCTION(shell32_module, SetCurrentProcessExplicitAppUserModelID); + } + + if (p_SetCurrentProcessExplicitAppUserModelID) + { + if (p_SetCurrentProcessExplicitAppUserModelID(L"SimonTatham.PuTTY") == S_OK) + { + return TRUE; + } + return FALSE; + } + /* Function doesn't exist, which is ok for Pre-7 systems */ + + return TRUE; + +} diff --git a/windows/winstuff.h b/windows/winstuff.h index c57ce6ea..b9602243 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -543,6 +543,7 @@ extern Backend serial_backend; void add_session_to_jumplist(const char * const sessionname); void remove_session_from_jumplist(const char * const sessionname); void clear_jumplist(void); +BOOL set_explicit_app_user_model_id(); /* * Extra functions in winstore.c over and above the interface in -- 2.45.1