From 63579cee4493c4a8e3d64348d644fd2eecaca055 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 21 Jan 2019 13:53:00 +0200 Subject: PPC v1.0.0 --- .../OS/DefaultOperationSystemManager.cs | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/OS') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/OS/DefaultOperationSystemManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/OS/DefaultOperationSystemManager.cs index 36b31e888..23722319c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/OS/DefaultOperationSystemManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/OS/DefaultOperationSystemManager.cs @@ -10,13 +10,14 @@ using Tango.PPC.Common.Scripting; namespace Tango.PPC.Common.OS { using System.Collections.ObjectModel; + using Tango.Core; using SLID = Guid; //SLID id declaration as typedef GUID SLID; in slpublic.h /// /// Represents the default windows activation manager. /// /// - public class DefaultOperationSystemManager : IOperationSystemManager + public class DefaultOperationSystemManager : ExtendedObject, IOperationSystemManager { #region Win32 @@ -43,6 +44,8 @@ namespace Tango.PPC.Common.OS { return Task.Factory.StartNew(() => { + LogManager.Log("Validating windows activation..."); + Guid ApplicationID = new Guid("55c92734-d682-4d71-983e-d6ec3f16059f"); //Application ID GUID http://technet.microsoft.com/en-us/library/dd772270.aspx SLID windowsSlid = (Guid)ApplicationID; try @@ -51,11 +54,12 @@ namespace Tango.PPC.Common.OS uint ResultInt = SLIsGenuineLocal(ref windowsSlid, ref genuineState, IntPtr.Zero); if (ResultInt == 0) { + LogManager.Log("OS activation status: " + genuineState.ToString()); return (genuineState == SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE); } else { - throw new InvalidOperationException("An error occurred while trying to get the OS activation status."); + throw LogManager.Log(new InvalidOperationException("An error occurred while trying to get the OS activation status.")); } } @@ -73,12 +77,21 @@ namespace Tango.PPC.Common.OS /// public async Task Activate(string activationKey) { - CmdCommand command = new CmdCommand("cscript", $"C:\\Windows\\System32\\slmgr.vbs -ipk {activationKey}"); - await command.Run(); + if (!(await IsActivated())) + { + CmdCommand command = new CmdCommand("cscript", $"C:\\Windows\\System32\\slmgr.vbs -ipk {activationKey}"); + await command.Run(); + + await Task.Delay(5000); - if (!await IsActivated()) + if (!await IsActivated()) + { + throw new ApplicationException("The activation was completed but activation status returned a false response."); + } + } + else { - throw new ApplicationException("The activation was completed but activation status returned a false response."); + LogManager.Log("Windows is already activated. Skipping activation..."); } } -- cgit v1.3.1