{"id":2338,"date":"2018-07-03T00:06:32","date_gmt":"2018-07-02T15:06:32","guid":{"rendered":"http:\/\/okamurax.com\/?p=2338"},"modified":"2018-07-03T02:24:17","modified_gmt":"2018-07-02T17:24:17","slug":"c-pc%e6%83%85%e5%a0%b1%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=2338","title":{"rendered":"C# PC\u60c5\u5831\u53d6\u5f97"},"content":{"rendered":"<p>PC\u540d\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6e08\u307f\u30a2\u30d7\u30ea\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u60c5\u5831\u3092\u53d6\u5f97<\/p>\n<pre class=\"lang:c# decode:true \" >using System;\r\nusing System.Collections.Generic;\r\nusing System.Windows.Forms;\r\n\r\nusing System.Net.NetworkInformation;\r\n\r\nnamespace PC\u60c5\u5831\r\n{\r\n    static class Program\r\n    {\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/ \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30e1\u30a4\u30f3 \u30a8\u30f3\u30c8\u30ea \u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002\r\n        \/\/\/ &lt;\/summary&gt;\r\n        [STAThread]\r\n        static void Main()\r\n        {\r\n            \/\/Application.EnableVisualStyles();\r\n            \/\/Application.SetCompatibleTextRenderingDefault(false);\r\n            \/\/Application.Run(new Form1());\r\n\r\n            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @\"\\info.txt\",false,System.Text.Encoding.GetEncoding(\"sjis\")))\r\n            {\r\n                sw.Write(GetRegDisplayName(@\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\") + \"\\n\\n\");\r\n                sw.Write(GetRegDisplayName(@\"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\") + \"\\n\\n\");\r\n                sw.Write(GetNicInfo());\r\n                sw.Write(\"OS Name: \" + GetOsType() + \"\\n\\n\");\r\n                sw.Write(\"OS Version: \" + Environment.OSVersion.ToString() + \"\\n\\n\");\r\n                sw.Write(\"OS Bit: \" + (Environment.Is64BitOperatingSystem ? \"64bit\" : \"32bit\") + \"\\n\\n\");\r\n                sw.Write(\"PC Name: \" + Environment.MachineName + \"\\n\\n\");\r\n                sw.Write(\"User Name: \" + Environment.UserName);\r\n            }\r\n            MessageBox.Show(\"\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002\");\r\n        }\r\n\r\n        static string GetOsType()\r\n        {\r\n            const string Path = @\"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\";\r\n            var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Path, false);\r\n            return (string)key.GetValue(\"ProductName\", \"\", Microsoft.Win32.RegistryValueOptions.DoNotExpandEnvironmentNames);\r\n        }\r\n\r\n        static string GetNicInfo()\r\n        {\r\n            string infoString = \"\";\r\n            foreach (NetworkInterface interfaces in NetworkInterface.GetAllNetworkInterfaces())\r\n            {\r\n                if (interfaces.OperationalStatus != OperationalStatus.Up) continue;\r\n\r\n                foreach(var unicast in interfaces.GetIPProperties().UnicastAddresses)\r\n                {\r\n                    if(unicast.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)\r\n                    {\r\n                        infoString += \"NIC Name: \" + interfaces.Name + \"\\n\" +\r\n                        \"MAC Address: \" + interfaces.GetPhysicalAddress() + \"\\n\" +\r\n                        \"IP Address: \" + unicast.Address + \"\\n\\n\";\r\n                    }\r\n                }\r\n\r\n            }\r\n            return infoString;\r\n        }\r\n\r\n        static string GetRegDisplayName(string regPath)\r\n        {\r\n            Microsoft.Win32.RegistryKey targetReg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, false);\r\n            if (targetReg == null) return \"\";\r\n\r\n            List&lt;string&gt; displayNameList = new List&lt;string&gt;();\r\n            foreach (string subKey in targetReg.GetSubKeyNames())\r\n            {\r\n                Microsoft.Win32.RegistryKey appkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath + \"\\\\\" + subKey, false);\r\n                if (appkey.GetValue(\"DisplayName\") == null) continue;\r\n\r\n                displayNameList.Add(appkey.GetValue(\"DisplayName\").ToString());\r\n            }\r\n            return string.Join(\"\\n\", displayNameList.ToArray());\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PC\u540d\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6e08\u307f\u30a2\u30d7\u30ea\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u60c5\u5831\u3092\u53d6\u5f97 using System; using System.Collections.Generic; using System.Windows.Forms;  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=2338\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# PC\u60c5\u5831\u53d6\u5f97&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-2338","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2338"}],"version-history":[{"count":2,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2338\/revisions"}],"predecessor-version":[{"id":2340,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2338\/revisions\/2340"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}