2019-07-03 12:27:02 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2019-07-03 12:27:02 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Lockdown.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2019-07-03 12:27:02 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Lockdown
|
|
|
|
|
{
|
|
|
|
|
public class SystemConfigurationUpdate : ISystemConfigurationUpdate
|
|
|
|
|
{
|
|
|
|
|
private ILogger logger;
|
|
|
|
|
|
|
|
|
|
public SystemConfigurationUpdate(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Starting system configuration update...");
|
|
|
|
|
|
|
|
|
|
var process = Process.Start(new ProcessStartInfo("cmd.exe", "/c \"gpupdate /force\"")
|
|
|
|
|
{
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
UseShellExecute = false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
logger.Info("Waiting for update to complete...");
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
|
|
var output = process.StandardOutput.ReadToEnd();
|
|
|
|
|
var lines = output.Split(new [] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
logger.Info($"Update has completed: {String.Join(" ", lines.Skip(1))}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error("Failed to update system configuration!", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExecuteAsync()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(new Action(Execute));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|