{"id":624,"date":"2016-12-06T11:56:07","date_gmt":"2016-12-06T02:56:07","guid":{"rendered":"http:\/\/astel-labs.net\/blog\/diary\/?p=624"},"modified":"2016-12-06T11:57:09","modified_gmt":"2016-12-06T02:57:09","slug":"06","status":"publish","type":"post","link":"https:\/\/astel-labs.net\/blog\/diary\/2016\/12\/06.html","title":{"rendered":"Windows\u306e\u30d7\u30ed\u30c0\u30af\u30c8ID\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>\u305f\u307e\u305f\u307e\u30d7\u30ed\u30c0\u30af\u30c8ID \u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3069\u3046\u3057\u305f\u3089\u3044\u3044\u306e\u304b\u8a71\u984c\u306b\u306a\u3063\u305f\u305f\u3081\u3001\u606f\u629c\u304d\u306b\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>OS \u306b\u9650\u3089\u305a\u3001\u69d8\u3005\u306a\u7ba1\u7406\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u30af\u30e9\u30b9\u3068\u3057\u3066\u3001\u300cManagementObjectSearcher\u300d\u30af\u30e9\u30b9\u304c\u5229\u7528\u3067\u304d\u307e\u3059\u3002<br \/>\nOS \u306b\u95a2\u3059\u308b\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3001ManagementObjectSearcher \u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u5f15\u6570\u3068\u3057\u3066 &#8220;SELECT * FROM Win32_OperatingSystem&#8221; \u3092\u5165\u529b\u3059\u308b\u3053\u3068\u3067\u69d8\u3005\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br \/>\n\u30d7\u30ed\u30c0\u30af\u30c8ID \u306f\u30af\u30a8\u30ea\u306b\u3088\u3063\u3066\u53d6\u5f97\u3055\u308c\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u3046\u3061\u3001PropertyData.Name \u304c \u300cSerialNumber\u300d\u306e\u30c7\u30fc\u30bf\u3068\u306a\u308b\u306e\u3067\u3001Where \u3067\u7279\u5b9a\u3057\u3066\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u69cb\u6587\u306b\u3088\u308b\u4f8b\uff08\u4e0b<\/p>\n<pre class=\"brush: csharp; gutter: true\">var productId = new ManagementObjectSearcher(&quot;SELECT * FROM Win32_OperatingSystem&quot;).Get()\r\n    .OfType&lt;ManagementObject&gt;()\r\n    .SelectMany((m) =&gt; m.Properties.OfType&lt;PropertyData&gt;().Select((p) =&gt; new { p.Name, p.Value }))\r\n    .Where((p) =&gt; p.Name == &quot;SerialNumber&quot;)\r\n    .Select((p) =&gt; (string)p.Value)\r\n    .FirstOrDefault();\r\n\r\nConsole.WriteLine(productId ?? &quot;\u60c5\u5831\u3092\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;);<\/pre>\n<p>\u30af\u30a8\u30ea\u69cb\u6587\u306b\u3088\u308b\u4f8b\uff08\u4e0b<\/p>\n<pre class=\"brush: csharp; gutter: true\">var productId = (from ManagementObject m in new ManagementObjectSearcher(&quot;SELECT * FROM Win32_OperatingSystem&quot;).Get()\r\n                    from PropertyData p in m.Properties\r\n                    where p.Name == &quot;SerialNumber&quot;\r\n                    select (string)p.Value).FirstOrDefault();\r\n\r\nConsole.WriteLine(productId ?? &quot;\u60c5\u5831\u3092\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;);<\/pre>\n<p>\u307e\u305f\u3001ManagementObjectSearcher \u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u6e21\u3059\u30af\u30a8\u30ea\u3092\u3001&#8221;SELECT SerialNumber FROM Win32_OperatingSystem&#8221; \u3068\u3059\u308b\u3068\u3001Where \u3092\u4f7f\u308f\u306a\u304f\u3066\u3082\u7c21\u5358\u306b\u7279\u5b9a\u3055\u305b\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<br \/>\nManagementObjectSearcher \u30af\u30e9\u30b9\u304b\u3089\u53d6\u5f97\u3059\u308b\u30c7\u30fc\u30bf\u578b\u304b\u3089\u7279\u5b9a\u306e\u5024\u3092\u63a2\u3057\u51fa\u3059\u306e\u306f\u82e5\u5e72\u624b\u9593\u3067\u3059\u304c\u3001\u6163\u308c\u308c\u3070\u69d8\u3005\u306a\u60c5\u5831\u3092\u7c21\u5358\u306b\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u300cWin32_OperatingSystem\u300d\u4ee5\u5916\u306b\u3082\u69d8\u3005\u306a\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u8abf\u3079\u3066\u307f\u308b\u3068\u9762\u767d\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u305f\u307e\u305f\u307e\u30d7\u30ed\u30c0\u30af\u30c8ID \u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3069\u3046\u3057\u305f\u3089\u3044\u3044\u306e\u304b\u8a71\u984c\u306b\u306a\u3063\u305f\u305f\u3081\u3001\u606f\u629c\u304d\u306b\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002 OS \u306b\u9650\u3089\u305a\u3001\u69d8\u3005\u306a\u7ba1\u7406\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u30af\u30e9\u30b9\u3068\u3057\u3066\u3001\u300cManagementObjectSearcher\u300d\u30af\u30e9\u30b9\u304c\u5229\u7528\u3067 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,4],"tags":[],"class_list":["post-624","post","type-post","status-publish","format-standard","hentry","category-c","category-4"],"_links":{"self":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/comments?post=624"}],"version-history":[{"count":7,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/posts\/624\/revisions\/631"}],"wp:attachment":[{"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/media?parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/categories?post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/astel-labs.net\/blog\/diary\/wp-json\/wp\/v2\/tags?post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}