Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Aug 12, 2018
1 parent c73222c commit 4a84603
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 0 deletions.
25 changes: 25 additions & 0 deletions wuauApp1/wuauApp1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wuauApp1", "wuauApp1\wuauApp1.csproj", "{8A051545-5118-4970-9BCF-29595E31003D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8A051545-5118-4970-9BCF-29595E31003D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A051545-5118-4970-9BCF-29595E31003D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A051545-5118-4970-9BCF-29595E31003D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A051545-5118-4970-9BCF-29595E31003D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5A300D8C-F39C-4E18-9B7C-0A0C9AFE5B3E}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions wuauApp1/wuauApp1/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
164 changes: 164 additions & 0 deletions wuauApp1/wuauApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WUApiLib;//this is required to use the Interfaces given by microsoft.

namespace wuauApp1
{
class Program
{
static void Main(string[] args)
{
UpdatesAvailable();
if (NeedsUpdate())
{
Console.WriteLine("There are updates for your computer available.");
EnableUpdateServices();//enables everything windows need in order to make an update
InstallUpdates(DownloadUpdates());
}
else
{
Console.WriteLine("There are no updates for your computer at this time.");
}
Console.WriteLine("Press any key to finalize the process");
Console.Read();
}
//this is my first try.. I can see the need for abstract classes here...
//but at least it gives most people a good starting point.
public static void InstalledUpdates()
{
UpdateSession UpdateSession = new UpdateSession();
IUpdateSearcher UpdateSearchResult = UpdateSession.CreateUpdateSearcher();
UpdateSearchResult.Online = true;//checks for updates online
ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=1 AND IsHidden=0");
//for the above search criteria refer to
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx
//Check the remakrs section
Console.WriteLine("The following updates are available");
foreach (IUpdate x in SearchResults.Updates)
{
Console.WriteLine(x.Title);
}
}
public static void UpdatesAvailable()
{
UpdateSession UpdateSession = new UpdateSession();
IUpdateSearcher UpdateSearchResult = UpdateSession.CreateUpdateSearcher();
UpdateSearchResult.Online = true;//checks for updates online
ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=0 AND IsPresent=0");
//for the above search criteria refer to
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx
//Check the remakrs section

foreach (IUpdate x in SearchResults.Updates)
{
Console.WriteLine(x.Title);
}
}
public static bool NeedsUpdate()
{
UpdateSession UpdateSession = new UpdateSession();
IUpdateSearcher UpdateSearchResult = UpdateSession.CreateUpdateSearcher();
UpdateSearchResult.Online = true;//checks for updates online
ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=0 AND IsPresent=0");
//for the above search criteria refer to
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=VS.85).aspx
//Check the remakrs section
if (SearchResults.Updates.Count > 0)
return true;
else return false;
}
public static UpdateCollection DownloadUpdates()
{
UpdateSession UpdateSession = new UpdateSession();
IUpdateSearcher SearchUpdates = UpdateSession.CreateUpdateSearcher();
ISearchResult UpdateSearchResult = SearchUpdates.Search("IsInstalled=0 and IsPresent=0");
UpdateCollection UpdateCollection = new UpdateCollection();
//Accept Eula code for each update
for (int i = 0; i < UpdateSearchResult.Updates.Count; i++)
{
IUpdate Updates = UpdateSearchResult.Updates[i];
if (Updates.EulaAccepted == false)
{
Updates.AcceptEula();
}
UpdateCollection.Add(Updates);
}
//Accept Eula ends here
//if it is zero i am not sure if it will trow an exception -- I havent tested it.
if (UpdateSearchResult.Updates.Count > 0)
{
UpdateCollection DownloadCollection = new UpdateCollection();
UpdateDownloader Downloader = UpdateSession.CreateUpdateDownloader();

for (int i = 0; i < UpdateCollection.Count; i++)
{
DownloadCollection.Add(UpdateCollection[i]);
}

Downloader.Updates = DownloadCollection;
Console.WriteLine("Downloading Updates... This may take several minutes.");


IDownloadResult DownloadResult = Downloader.Download();
UpdateCollection InstallCollection = new UpdateCollection();
for (int i = 0; i < UpdateCollection.Count; i++)
{
if (DownloadCollection[i].IsDownloaded)
{
InstallCollection.Add(DownloadCollection[i]);
}
}
Console.WriteLine("Download Finished");
return InstallCollection;
}
else
return UpdateCollection;
}
public static void InstallUpdates(UpdateCollection DownloadedUpdates)
{
Console.WriteLine("Installing updates now...");
UpdateSession UpdateSession = new UpdateSession();
UpdateInstaller InstallAgent = UpdateSession.CreateUpdateInstaller() as UpdateInstaller;
InstallAgent.Updates = DownloadedUpdates;

//Starts a synchronous installation of the updates.
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods
if (DownloadedUpdates.Count > 0)
{
IInstallationResult InstallResult = InstallAgent.Install();
if (InstallResult.ResultCode == OperationResultCode.orcSucceeded)
{
Console.WriteLine("Updates installed succesfully");
if (InstallResult.RebootRequired == true)
{
Console.WriteLine("Reboot is required for one of more updates.");
}
}
else
{
Console.WriteLine("Updates failed to install do it manually");
}
}
else
{
Console.WriteLine("The computer that this script was executed is up to date");
}

}
public static void EnableUpdateServices()
{
IAutomaticUpdates updates = new AutomaticUpdates();
if (!updates.ServiceEnabled)
{
Console.WriteLine("Not all updates services where enabled. Enabling Now" + updates.ServiceEnabled);
updates.EnableService();
Console.WriteLine("Service enable success");
}


}
}
}
36 changes: 36 additions & 0 deletions wuauApp1/wuauApp1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("wuauApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("wuauApp1")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("8a051545-5118-4970-9bcf-29595e31003d")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
63 changes: 63 additions & 0 deletions wuauApp1/wuauApp1/wuauApp1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8A051545-5118-4970-9BCF-29595E31003D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>wuauApp1</RootNamespace>
<AssemblyName>wuauApp1</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<COMReference Include="WUApiLib">
<Guid>{B596CC9F-56E5-419E-A622-E01BB457431E}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit 4a84603

Please sign in to comment.