[GPO][MWB]Add policy to disable service mode (#37366)

* [MWB]Add policy to disable service mode

* Add restart note

* Tweak settings to disable setting

* Tweak infobars

* Policy should be machine only
This commit is contained in:
Jaime Bernardo
2025-02-12 18:49:26 +00:00
committed by GitHub
parent e0cb4018ab
commit 0c7a1dd316
13 changed files with 109 additions and 12 deletions

View File

@@ -92,6 +92,17 @@ namespace MouseWithoutBorders.Class
bool serviceMode = firstArg == ServiceModeArg;
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMwbAllowServiceModeValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
if (runningAsSystem)
{
Logger.Log("Can't run as a service. It's not allowed according to GPO policy. Please contact your systems administrator.");
return;
}
serviceMode = false;
}
// If we're started from the .dll module or from the service process, we should
// assume the service mode.
if (serviceMode && !runningAsSystem)

View File

@@ -1090,6 +1090,11 @@ namespace MouseWithoutBorders.Class
{
get
{
if (GPOWrapper.GetConfiguredMwbAllowServiceModeValue() == GpoRuleConfigured.Disabled)
{
return false;
}
lock (_loadingSettingsLock)
{
return _properties.UseService;
@@ -1098,6 +1103,11 @@ namespace MouseWithoutBorders.Class
set
{
if (AllowServiceModeIsGpoConfigured)
{
return;
}
lock (_loadingSettingsLock)
{
_properties.UseService = value;
@@ -1109,6 +1119,10 @@ namespace MouseWithoutBorders.Class
}
}
[CmdConfigureIgnore]
[JsonIgnore]
internal bool AllowServiceModeIsGpoConfigured => GPOWrapper.GetConfiguredMwbAllowServiceModeValue() == GpoRuleConfigured.Disabled;
// Note(@htcfreek): Settings UI CheckBox is disabled in frmMatrix.cs > FrmMatrix_Load()
internal bool SendErrorLogV2
{

View File

@@ -28,7 +28,8 @@ namespace MouseWithoutBordersService
[STAThread]
private static void Main()
{
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled
|| PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMwbAllowServiceModeValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled )
{
// TODO: Add logging.
// Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");

View File

@@ -363,7 +363,11 @@ private:
void update_state_from_settings(const PowerToysSettings::PowerToyValues& values)
{
const bool new_run_in_service_mode = values.get_bool_value(USE_SERVICE_PROPERTY_NAME).value_or(false);
bool new_run_in_service_mode = values.get_bool_value(USE_SERVICE_PROPERTY_NAME).value_or(false);
if (powertoys_gpo::getConfiguredMwbAllowServiceModeValue() == powertoys_gpo::gpo_rule_configured_disabled)
{
new_run_in_service_mode = false;
}
if (new_run_in_service_mode != run_in_service_mode)
{