Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RamFlusher.exe -- minified, silent, and "stand-alone"
- // contact me (Alaestor) via http://discord.FutureGadgetLab.net/
- #define WINVER _WIN32_WINNT_WIN7
- #include <stdexcept>
- #include <vector>
- #include <windows.h>
- #include <psapi.h>
- bool RanAsAdmin() // stolen from our FGL.h standard header
- {
- TOKEN_ELEVATION te;
- if (void* h = nullptr;
- OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h))
- {
- if (h == nullptr) return false;
- unsigned long cbSize = sizeof(TOKEN_ELEVATION);
- GetTokenInformation(h, TokenElevation, &te, sizeof(te), &cbSize);
- CloseHandle(h);
- }
- return te.TokenIsElevated ? true : false;
- }
- int main()
- {
- if (!RanAsAdmin()) // if you get a GUI, use a prompt instead
- throw std::runtime_error("Must be run as administrator to work!");
- // get pids
- static constexpr const std::size_t MaxPIDs = 1024;
- std::vector<unsigned long> pids(MaxPIDs);
- pids.resize(MaxPIDs); // "theoretically" unneeded
- if (unsigned long bytesWriten = 0;
- EnumProcesses(pids.data(), pids.size(), &bytesWriten))
- { pids.resize(bytesWriten / sizeof(decltype(pids)::value_type)); }
- else throw std::runtime_error("EnumProcesses() failed");
- // flush pids down toilet
- static constexpr const unsigned long AccessFlags =
- PROCESS_QUERY_INFORMATION | PROCESS_SET_QUOTA;
- for (const auto& pid : pids) // best effort
- if (const auto& h(OpenProcess(AccessFlags, false, pid)); h != nullptr)
- { EmptyWorkingSet(h); CloseHandle(h); }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement