11#include "main.h"
22#include <phdk.h>
3- #include "phf\runas.h"
43#include "resource.h"
54
65LOGICAL DllMain (
@@ -23,8 +22,17 @@ LOGICAL DllMain(
2322 info -> DisplayName = L"Emergency" ;
2423 info -> Author = L"TETYYS" ;
2524 info -> Description = L"Brings up ProcessHacker in emergency situations" ;
25+ info -> Url = L"http://wj32.org/processhacker/forums/viewtopic.php?f=18&t=1954" ;
2626 info -> HasOptions = TRUE;
2727
28+ ULONG major , minor ;
29+ PhGetPhVersionNumbers (& major , & minor , NULL , NULL );
30+ if (major < 2 || minor < 36 ) {
31+ PhShowMessage (NULL , MB_ICONERROR , L"%s%d%d%d%s" , L"Your Process Hacker version is not supported by Emergency plugin, please update Process Hacker or plugin will stay disabled. (Requires revision 2.36)" );
32+ info -> HasOptions = FALSE;
33+ return FALSE;
34+ }
35+
2836 Switching = FALSE;
2937
3038 {
@@ -198,7 +206,9 @@ INT_PTR CALLBACK OptionsDlgProc(
198206 break ;
199207 case IDOK :
200208 {
201- PhSetStringSetting (DESKTOP_SETTING , PHA_GET_DLGITEM_TEXT (hwndDlg , IDC_DESKTOP )-> Buffer );
209+ PPH_STRING setting = PhGetWindowText (GetDlgItem (hwndDlg , IDC_DESKTOP )); {
210+ PhSetStringSetting (DESKTOP_SETTING , setting -> Buffer );
211+ } PhDereferenceObject (setting );
202212 EndDialog (hwndDlg , IDOK );
203213 }
204214 break ;
@@ -249,7 +259,7 @@ LRESULT CALLBACK LowLevelKeyboardProc(
249259 _In_ LPARAM lParam
250260 )
251261{
252- ULONG identifier = wParam ;
262+ WPARAM identifier = wParam ;
253263 KBDLLHOOKSTRUCT * kbd = (KBDLLHOOKSTRUCT * )lParam ;
254264 BOOL enabled ;
255265
@@ -280,19 +290,17 @@ LRESULT CALLBACK LowLevelKeyboardProc(
280290 Switching = TRUE;
281291 // GO GO GO!
282292
283- WCHAR fullPath [MAX_PATH ];
284- GetModuleFileName (NULL , fullPath , MAX_PATH );
285-
286293 ULONG sessId ;
287294 PhGetProcessSessionId (GetCurrentProcess (), & sessId );
288-
289- /*EmergencyDesktopFull = ;
290- ULONG_PTR index = PhFindCharInString(EmergencyDesktopFull, 0, L'\\') + 1;
291- EmergencyDesktop = PhSubstring(EmergencyDesktopFull, index, EmergencyDesktopFull->Length - index);*/
295+
292296 PPH_STRING desktopFull = PhGetStringSetting (DESKTOP_SETTING );
293297 ULONG_PTR index = PhFindCharInString (desktopFull , 0 , L'\\' ) + 1 ;
294298 PPH_STRING desktop = PhSubstring (desktopFull , index , desktopFull -> Length - index );
295- PPH_STRING cmd = PhFormatString (L"--EmergencySwitch %s" , desktop -> Buffer );
299+
300+ PPH_STRING cmd ;
301+ PPH_STRING app = PhGetApplicationFileName (); {
302+ cmd = PhFormatString (L"\"%s\" -newinstance --EmergencySwitch %s" , app -> Buffer , desktop -> Buffer );
303+ } PhDereferenceObject (app );
296304
297305 if (!DesktopExists (desktop )) {
298306 if (CreateDesktop (desktop -> Buffer , NULL , NULL , 0 , DESKTOP_ALL_ACCESS , NULL ) == NULL ) {
@@ -303,12 +311,12 @@ LRESULT CALLBACK LowLevelKeyboardProc(
303311 PhDereferenceObject (cmd );
304312 goto nextHook ;
305313 }
314+ // do NOT close the desktop!
306315 }
307-
308- PhExecuteRunAsCommand2 (NULL , fullPath , cmd -> Buffer , L"NT AUTHORITY\\SYSTEM" , PhGetStringOrEmpty (NULL ), LOGON32_LOGON_SERVICE , NULL , sessId , desktopFull -> Buffer , FALSE);
309- // do NOT close the desktop!
310-
311316 PhDereferenceObject (desktop );
317+
318+ PhExecuteRunAsCommand2 (NULL , cmd -> Buffer , L"NT AUTHORITY\\SYSTEM" , PhGetStringOrEmpty (NULL ), LOGON32_LOGON_SERVICE , NULL , sessId , desktopFull -> Buffer , FALSE);
319+
312320 PhDereferenceObject (desktopFull );
313321 PhDereferenceObject (cmd );
314322 Sleep (2000 );
0 commit comments