Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Oct 6, 2018
1 parent b184d62 commit cc19eba
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 63 deletions.
8 changes: 4 additions & 4 deletions wumgr/Common/FileOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ static public string FormatSize(decimal size)
if (size == 0)
return "";
if (size > 1024 * 1024 * 1024)
return (size / (1024 * 1024 * 1024)).ToString("F") + " Gb";
return (size / (1024 * 1024 * 1024)).ToString("F") + " GB";
if (size > 1024 * 1024)
return (size / (1024 * 1024)).ToString("F") + " Mb";
return (size / (1024 * 1024)).ToString("F") + " MB";
if (size > 1024)
return (size / (1024)).ToString("F") + " Kb";
return ((Int64)size).ToString() + " b";
return (size / (1024)).ToString("F") + " KB";
return ((Int64)size).ToString() + " B";
}

static public bool MoveFile(string from, string to, bool Overwrite = false)
Expand Down
132 changes: 75 additions & 57 deletions wumgr/GPO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static public void HideUpdatePage(bool hide = true)
static public bool IsUpdatePageHidden()
{
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer");
string value = subKey.GetValue("SettingsPageVisibility", "").ToString();
string value = subKey == null ? null : subKey.GetValue("SettingsPageVisibility", "").ToString();
return value.Contains("hide:windowsupdate");
}

Expand Down Expand Up @@ -173,13 +173,11 @@ static public void BlockMS(bool block = true)
static public int GetBlockMS()
{
var subKey = Registry.LocalMachine.OpenSubKey(mWuGPO);
object value_block = subKey.GetValue("DoNotConnectToWindowsUpdateInternetLocations");
/*subKey.DeleteValue("WUServer", false);
subKey.DeleteValue("WUStatusServer", false);
subKey.DeleteValue("UpdateServiceUrlAlternate", false);*/

object value_block = subKey == null ? null : subKey.GetValue("DoNotConnectToWindowsUpdateInternetLocations");

var subKey2 = Registry.LocalMachine.OpenSubKey(mWuGPO + @"\AU");
object value_wsus = subKey2.GetValue("UseWUServer");
object value_wsus = subKey2 == null ? null : subKey2.GetValue("UseWUServer");

if ((value_block != null && (int)value_block == 1) && (value_wsus != null && (int)value_wsus == 1))
return 1; // CheckState.Checked;
Expand All @@ -191,7 +189,7 @@ static public int GetBlockMS()

static public void SetStoreAU(bool disable)
{
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\Microsoft\WindowsStore");
var subKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Policies\Microsoft\WindowsStore", true);
//var subKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate", true);
if (disable)
subKey.SetValue("AutoDownload", 2);
Expand All @@ -202,8 +200,8 @@ static public void SetStoreAU(bool disable)
static public bool GetStoreAU()
{
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\Microsoft\WindowsStore");
//var subKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate", true);
object value_block = subKey.GetValue("AutoDownload");
//var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate");
object value_block = subKey == null ? null : subKey.GetValue("AutoDownload");
return (value_block != null && (int)value_block == 2);
}

Expand All @@ -224,26 +222,37 @@ static public void DisableAU(bool disable)
static public void ConfigSvc(string name, ServiceStartMode mode)
{
ServiceController svc = new ServiceController(name);
bool showErr = false;
try
{
if (mode == ServiceStartMode.Disabled && svc.Status == ServiceControllerStatus.Running)
{
svc.Stop();
showErr = false;
}

// Note: for UsoSvc and for WaaSMedicSvc this call fails with an access error so we have to set the registry
//ServiceHelper.ChangeStartMode(svc, mode);
}
catch (Exception err)
{
AppLog.Line("Error: " + err.Message);
if(showErr)
AppLog.Line("Error Stoping Service: {0}", name);
}
svc.Close();

var subKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + name, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.SetValue | RegistryRights.ChangePermissions | RegistryRights.TakeOwnership);
if (subKey == null)
{
AppLog.Line("Service {0} does not exist", name);
return;
}

subKey.SetValue("Start", (int)mode);

var ac = subKey.GetAccessControl();
AuthorizationRuleCollection rules = ac.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier)); // get as SID not string
// cleanup old roule
// cleanup old roule
foreach (RegistryAccessRule rule in rules)
{
if (rule.IdentityReference.Value.Equals(FileOps.SID_System))
Expand Down Expand Up @@ -276,62 +285,71 @@ public enum Respect

static public Respect GetRespect()
{
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
//string edition = subKey.GetValue("EditionID", "").ToString();
string name = subKey.GetValue("ProductName", "").ToString();
string type = subKey.GetValue("InstallationType", "").ToString();
try
{
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
//string edition = subKey.GetValue("EditionID", "").ToString();
string name = subKey.GetValue("ProductName", "").ToString();
string type = subKey.GetValue("InstallationType", "").ToString();

if (GetWinVersion() < 10.0f || type.Equals("Server", StringComparison.CurrentCultureIgnoreCase) || name.Contains("Education") || name.Contains("Enterprise"))
return Respect.Full;
if (GetWinVersion() < 10.0f || type.Equals("Server", StringComparison.CurrentCultureIgnoreCase) || name.Contains("Education") || name.Contains("Enterprise"))
return Respect.Full;

if (type.Equals("Client", StringComparison.CurrentCultureIgnoreCase))
{
if(name.Contains("Pro"))
return Respect.Partial;
if (name.Contains("Home"))
return Respect.None;
if (type.Equals("Client", StringComparison.CurrentCultureIgnoreCase))
{
if (name.Contains("Pro"))
return Respect.Partial;
if (name.Contains("Home"))
return Respect.None;
}
}
catch { }
return Respect.Unknown;
}

static public float GetWinVersion()
{
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
//string Majorversion = subKey.GetValue("CurrentMajorVersionNumber", "0").ToString(); // this is 10 on 10 but not present on earlier editions
string version = subKey.GetValue("CurrentVersion", "0").ToString();
float version_num = float.Parse(version, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
//string name = subKey.GetValue("ProductName", "").ToString();

/*
Operating system Version number
---------------------------- --------------
Windows 10 6.3 WTF why not 10
Windows Server 2016 6.3 WTF why not 10
Windows 8.1 6.3
Windows Server 2012 R2 6.3
Windows 8 6.2
Windows Server 2012 6.2
Windows 7 6.1
Windows Server 2008 R2 6.1
Windows Server 2008 6.0
Windows Vista 6.0
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 64-Bit Edition 5.2
Windows XP 5.1
Windows 2000 5.0
Windows ME 4.9
Windows 98 4.10
*/

if (version_num >= 6.3)
try
{
//!name.Contains("8.1") && !name.Contains("2012 R2");
int build = MiscFunc.parseInt(subKey.GetValue("CurrentBuildNumber", "0").ToString());
if (build >= 10000) // 1507 RTM release
return 10.0f;
var subKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
//string Majorversion = subKey.GetValue("CurrentMajorVersionNumber", "0").ToString(); // this is 10 on 10 but not present on earlier editions
string version = subKey.GetValue("CurrentVersion", "0").ToString();
float version_num = float.Parse(version, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
//string name = subKey.GetValue("ProductName", "").ToString();

/*
Operating system Version number
---------------------------- --------------
Windows 10 6.3 WTF why not 10
Windows Server 2016 6.3 WTF why not 10
Windows 8.1 6.3
Windows Server 2012 R2 6.3
Windows 8 6.2
Windows Server 2012 6.2
Windows 7 6.1
Windows Server 2008 R2 6.1
Windows Server 2008 6.0
Windows Vista 6.0
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 64-Bit Edition 5.2
Windows XP 5.1
Windows 2000 5.0
Windows ME 4.9
Windows 98 4.10
*/

if (version_num >= 6.3)
{
//!name.Contains("8.1") && !name.Contains("2012 R2");
int build = MiscFunc.parseInt(subKey.GetValue("CurrentBuildNumber", "0").ToString());
if (build >= 10000) // 1507 RTM release
return 10.0f;
}
return version_num;
}
return version_num;
catch { }
return 0.0f;
}
}
}
2 changes: 1 addition & 1 deletion wumgr/WuAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ protected void OnUpdatesFound(ISearchJob searchJob)
}
catch (Exception err)
{
AppLog.Line("Search for updats failed");
AppLog.Line("Search for updates failed");
LogError(err);
OnFinished(RetCodes.InternalError);
return;
Expand Down
2 changes: 1 addition & 1 deletion wumgr/WuMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ void LoadList(List<MsUpdate> List)
Update.Title,
Update.Category,
Update.KB,
FileOps.FormatSize(Update.Size),
Update.Date.ToString("dd.MM.yyyy"),
FileOps.FormatSize(Update.Size),
State});

items[i].Tag = Update;
Expand Down

0 comments on commit cc19eba

Please sign in to comment.