using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace PC情報
{
static class Program
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\info.txt",false,System.Text.Encoding.GetEncoding("sjis")))
{
sw.Write(GetRegDisplayName(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") + "\n\n");
sw.Write(GetRegDisplayName(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") + "\n\n");
sw.Write(GetNicInfo());
sw.Write("OS Name: " + GetOsType() + "\n\n");
sw.Write("OS Version: " + Environment.OSVersion.ToString() + "\n\n");
sw.Write("OS Bit: " + (Environment.Is64BitOperatingSystem ? "64bit" : "32bit") + "\n\n");
sw.Write("PC Name: " + Environment.MachineName + "\n\n");
sw.Write("User Name: " + Environment.UserName);
}
MessageBox.Show("終了しました。");
}
static string GetOsType()
{
const string Path = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Path, false);
return (string)key.GetValue("ProductName", "", Microsoft.Win32.RegistryValueOptions.DoNotExpandEnvironmentNames);
}
static string GetNicInfo()
{
string infoString = "";
foreach (NetworkInterface interfaces in NetworkInterface.GetAllNetworkInterfaces())
{
if (interfaces.OperationalStatus != OperationalStatus.Up) continue;
foreach(var unicast in interfaces.GetIPProperties().UnicastAddresses)
{
if(unicast.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
infoString += "NIC Name: " + interfaces.Name + "\n" +
"MAC Address: " + interfaces.GetPhysicalAddress() + "\n" +
"IP Address: " + unicast.Address + "\n\n";
}
}
}
return infoString;
}
static string GetRegDisplayName(string regPath)
{
Microsoft.Win32.RegistryKey targetReg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, false);
if (targetReg == null) return "";
List<string> displayNameList = new List<string>();
foreach (string subKey in targetReg.GetSubKeyNames())
{
Microsoft.Win32.RegistryKey appkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath + "\\" + subKey, false);
if (appkey.GetValue("DisplayName") == null) continue;
displayNameList.Add(appkey.GetValue("DisplayName").ToString());
}
return string.Join("\n", displayNameList.ToArray());
}
}
}