PC名、ユーザー名、インストール済みアプリ、ネットワーク情報を取得
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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()); } } } |