mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
* Add GPOWrapper headers and C++/WinRT library * Check GPO before starting utilities * Show message on GPO having disabled preview panes. * Don't generate thumbnails if GPO disabled * Fix FancyZonesEditor unable to recognize GPOWrapper * Move settings view models to the settings project * Use GPO to block enabling utilities in Settings * Hide context menu entries when gpo disables utilities * Apply gpo policies when enabling PowerToys on runner * Add version and metadata to dll * Add GPOWrapper to the installer * Fix MSBuild errors on WPF apps by using Projection * Signing * Add gpo files and publish them * Add GPO policies to the bug report tool * Add some documentation for using GPO * Mention support to actual lowest supported version of Windows * Move PowerToys to the root of administrative templates tree * Save policies on Software\Policies\PowerToys * Support both machine and user scopes * Fix documentation to reference computer and user scopes * Mention incompatibility with outlook in gpo * Set a better folder structure for gpo assets * Move PDF Handler warning to the description * Update doc/gpo/README.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Add actual minimum version of PowerToys to gpo files * Fix identation * Remove GPOWrapper Readme * Add Active Directory instructions to doc Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
#include "pch.h"
|
|
#include <common/utils/window.h>
|
|
#include <common/utils/ProcessWaiter.h>
|
|
#include <common/utils/winapi_error.h>
|
|
#include <common/utils/logger_helper.h>
|
|
#include <common/utils/UnhandledExceptionHandler.h>
|
|
#include <common/utils/gpo.h>
|
|
#include <keyboardmanager/common/KeyboardManagerConstants.h>
|
|
#include <keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.h>
|
|
#include <keyboardmanager/KeyboardManagerEngineLibrary/trace.h>
|
|
|
|
const std::wstring instanceMutexName = L"Local\\PowerToys_KBMEngine_InstanceMutex";
|
|
|
|
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PWSTR lpCmdLine, _In_ int nCmdShow)
|
|
{
|
|
winrt::init_apartment();
|
|
LoggerHelpers::init_logger(KeyboardManagerConstants::ModuleName, L"Engine", LogSettings::keyboardManagerLoggerName);
|
|
|
|
if (powertoys_gpo::getConfiguredKeyboardManagerEnabledValue() == powertoys_gpo::gpo_rule_configured_disabled)
|
|
{
|
|
Logger::warn(L"Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
|
return 0;
|
|
}
|
|
|
|
InitUnhandledExceptionHandler();
|
|
|
|
auto mutex = CreateMutex(nullptr, true, instanceMutexName.c_str());
|
|
if (mutex == nullptr)
|
|
{
|
|
Logger::error(L"Failed to create mutex. {}", get_last_error_or_default(GetLastError()));
|
|
}
|
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
{
|
|
Logger::warn(L"KBM engine instance is already running");
|
|
return 0;
|
|
}
|
|
|
|
Trace::RegisterProvider();
|
|
|
|
std::wstring pid = std::wstring(lpCmdLine);
|
|
if (!pid.empty())
|
|
{
|
|
auto mainThreadId = GetCurrentThreadId();
|
|
ProcessWaiter::OnProcessTerminate(pid, [mainThreadId](int err) {
|
|
if (err != ERROR_SUCCESS)
|
|
{
|
|
Logger::error(L"Failed to wait for parent process exit. {}", get_last_error_or_default(err));
|
|
}
|
|
else
|
|
{
|
|
Logger::trace(L"PowerToys runner exited.");
|
|
}
|
|
|
|
Logger::trace(L"Exiting KeyboardManager engine");
|
|
PostThreadMessage(mainThreadId, WM_QUIT, 0, 0);
|
|
});
|
|
}
|
|
|
|
auto kbm = KeyboardManager();
|
|
kbm.StartLowlevelKeyboardHook();
|
|
|
|
run_message_loop();
|
|
|
|
kbm.StopLowlevelKeyboardHook();
|
|
Trace::UnregisterProvider();
|
|
|
|
return 0;
|
|
}
|