Skip to content

Commit ecc3e32

Browse files
committed
v1.0.2
v1.0.2 - Disallows the possibility of pausing explorer.exe, because nothing good can come of that.
1 parent 2fd1d78 commit ecc3e32

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Main.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ _NtResumeProcess NtResumeProcess = (_NtResumeProcess)GetProcAddress(GetModuleHan
2323
NOTIFYICONDATA G_TrayNotifyIconData;
2424
HANDLE 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
{

UniversalPauseButton.rc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)