@@ -23,6 +23,26 @@ _NtResumeProcess NtResumeProcess = (_NtResumeProcess)GetProcAddress(GetModuleHan
2323NOTIFYICONDATA G_TrayNotifyIconData;
2424HANDLE G_Mutex;
2525
26+ // NOTE(Ryan): This function returns true if the string ends with the specified Suffix/substring.
27+ // Uses wide characters. Not case sensitive.
28+ int StringEndsWithW (_In_ const wchar_t *Str, _In_ const wchar_t *Suffix)
29+ {
30+ if (Str == NULL || Suffix == NULL )
31+ {
32+ return 0 ;
33+ }
34+
35+ size_t str_len = wcslen (Str);
36+ size_t suffix_len = wcslen (Suffix);
37+
38+ if (suffix_len > str_len)
39+ {
40+ return 0 ;
41+ }
42+
43+ return 0 == _wcsnicmp (Str + str_len - suffix_len, Suffix, suffix_len);
44+ }
45+
2646// The WindowProc (callback) for WinMain's WindowClass.
2747// Basically the system tray does nothing except lets the user know that it's running.
2848// If the user clicks the tray icon it will ask if they want to exit the app.
@@ -166,9 +186,21 @@ int CALLBACK WinMain(_In_ HINSTANCE Instance, _In_opt_ HINSTANCE, _In_ LPSTR, _I
166186
167187 if (PreviouslySuspendedProcessID == 0 )
168188 {
169- NtSuspendProcess (ProcessHandle);
170- PreviouslySuspendedProcessID = ProcessID;
171- GetWindowText (ForegroundWindow, PreviouslySuspendedProcessText, sizeof (PreviouslySuspendedProcessText) / sizeof (wchar_t ));
189+ // I won't let you pause your shell. Nothing good will come of that.
190+ // Later I will get the user's shell from the registry, just to cover the 0.001% case
191+ // that the user has a custom shell.
192+ wchar_t ImageFileName[MAX_PATH] = { 0 };
193+ GetProcessImageFileName (ProcessHandle, ImageFileName, sizeof (ImageFileName) / sizeof (wchar_t ));
194+ if (!StringEndsWithW (ImageFileName, L" explorer.exe" ))
195+ {
196+ NtSuspendProcess (ProcessHandle);
197+ PreviouslySuspendedProcessID = ProcessID;
198+ GetWindowText (ForegroundWindow, PreviouslySuspendedProcessText, sizeof (PreviouslySuspendedProcessText) / sizeof (wchar_t ));
199+ }
200+ else
201+ {
202+ MessageBox (NULL , L" You cannot pause your shell." , L" UniversalPauseButton Error" , MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
203+ }
172204 }
173205 else if (PreviouslySuspendedProcessID == ProcessID)
174206 {
0 commit comments