Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
インストールされている .NET Framework のパッチを調べる (C#, VisualStudio, Show Installed Updates of .NET Framework)
// -------------------------------------------------------------------------
// 以下のURLから拝借
// https://msdn.microsoft.com/ja-jp/library/hh925567(v=vs.110).aspx
// -------------------------------------------------------------------------
namespace ShowInstalledDotNetPatches
{
using System;
using Microsoft.Win32;
/// <summary>
/// インストールされている .NET Framework の更新プログラムを出力します。
/// </summary>
internal static class Program
{
/// <summary>
/// アプリケーションエントリポイント
/// </summary>
private static void Main()
{
using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Updates"))
{
if (baseKey == null)
{
return;
}
foreach (var baseKeyName in baseKey.GetSubKeyNames())
{
if (baseKeyName.Contains(".NET Framework") || baseKeyName.StartsWith("KB") || baseKeyName.Contains(".NETFramework"))
{
using (var updateKey = baseKey.OpenSubKey(baseKeyName))
{
if (updateKey == null)
{
continue;
}
var name = (string)updateKey.GetValue("PackageName", string.Empty);
Console.WriteLine(baseKeyName + " " + name);
foreach (var kbKeyName in updateKey.GetSubKeyNames())
{
using (var kbKey = updateKey.OpenSubKey(kbKeyName))
{
if (kbKey == null)
{
continue;
}
name = (string)kbKey.GetValue("PackageName", string.Empty);
Console.WriteLine(" " + kbKeyName + " " + name);
if (kbKey.SubKeyCount > 0)
{
foreach (var sbKeyName in kbKey.GetSubKeyNames())
{
using (var sbSubKey = kbKey.OpenSubKey(sbKeyName))
{
name = (string)sbSubKey.GetValue("PackageName", string.Empty);
if (name == string.Empty)
{
name = (string)sbSubKey.GetValue("Description", string.Empty);
}
Console.WriteLine(" " + sbKeyName + " " + name);
}
}
}
}
}
}
}
}
}
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment