{"id":33509,"date":"2013-10-03T17:37:10","date_gmt":"2013-10-03T16:37:10","guid":{"rendered":"http:\/\/www.fuhaijun.com\/?p=33509"},"modified":"2024-11-06T11:18:46","modified_gmt":"2024-11-06T03:18:46","slug":"powershell%e8%af%bb%e5%8f%96windows%e4%ba%a7%e5%93%81%e5%af%86%e9%92%a5","status":"publish","type":"post","link":"https:\/\/www.fuhaijun.com\/?p=33509","title":{"rendered":"PowerShell\u8bfb\u53d6Windows\u4ea7\u54c1\u5bc6\u94a5"},"content":{"rendered":"<p>\u4e4b\u524d\u5927\u591a\u6570\u4eba\u53ef\u80fd\u7528\u8fc7VBS\u8bfb\u53d6Windows\u4ea7\u54c1\u5bc6\u94a5\u7684VBS\u811a\u672c\uff0cVBS\u811a\u672c\u901a\u5e38\u90fd\u6bd4\u8f83\u9690\u6666\u3001\u96be\u61c2\uff0c\u4eca\u5929\u5fd9\u91cc\u5077\u95f2\uff0c\u968f\u624b\u5199\u4e86\u4e00\u4e2a\u7528\u4e8e\u8bfb\u53d6Windows\u4ea7\u54c1\u5bc6\u94a5\u7684PowerShell\u811a\u672c\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre style=\"width: 167.69%; font: 9pt verdana, fixedsys, verdana, tahoma; height: 595px\"><span class=\"line_num\">        =====\u6587\u4ef6\u540d\uff1aGet-WindowsProductKey.ps1=====<\/span>\n<font color=\"#0000ff\">function<\/font> Get-WindowsProductKey([<font color=\"#0000ff\">string<\/font>]$computer)\n{\n\n$comments =@'\n<font color=\"#008000\">author:fuhj(powershell#live.cn ,http:\/\/fuhaijun.com) \nexample: Get-WindowsProductKey .<\/font>\n'@\n$reg = [WMIClass] (<font color=\"#ff00ff\">&quot;\\\\&quot;<\/font> + $computer + <font color=\"#ff00ff\">&quot;\\root\\default:StdRegProv&quot;<\/font>)\n$values = [byte[]]($reg.getbinaryvalue(2147483650,<font color=\"#ff00ff\">&quot;SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion&quot;<\/font>,<font color=\"#ff00ff\">&quot;DigitalProductId&quot;<\/font>).uvalue)\n$lookup = [char[]](<font color=\"#ff00ff\">&quot;B&quot;<\/font>,<font color=\"#ff00ff\">&quot;C&quot;<\/font>,<font color=\"#ff00ff\">&quot;D&quot;<\/font>,<font color=\"#ff00ff\">&quot;F&quot;<\/font>,<font color=\"#ff00ff\">&quot;G&quot;<\/font>,<font color=\"#ff00ff\">&quot;<\/font><font color=\"#008080\">H<\/font>&quot;,<font color=\"#ff00ff\">&quot;J&quot;<\/font>,<font color=\"#ff00ff\">&quot;K&quot;<\/font>,<font color=\"#ff00ff\">&quot;M&quot;<\/font>,<font color=\"#ff00ff\">&quot;P&quot;<\/font>,<font color=\"#ff00ff\">&quot;Q&quot;<\/font>,<font color=\"#ff00ff\">&quot;<\/font><font color=\"#008080\">R<\/font>&quot;,<font color=\"#ff00ff\">&quot;T&quot;<\/font>,<font color=\"#ff00ff\">&quot;V&quot;<\/font>,<font color=\"#ff00ff\">&quot;W&quot;<\/font>,<font color=\"#ff00ff\">&quot;X&quot;<\/font>,<font color=\"#ff00ff\">&quot;Y&quot;<\/font>,<font color=\"#ff00ff\">&quot;2&quot;<\/font>,<font color=\"#ff00ff\">&quot;3&quot;<\/font>,<font color=\"#ff00ff\">&quot;4&quot;<\/font>,<font color=\"#ff00ff\">&quot;6&quot;<\/font>,<font color=\"#ff00ff\">&quot;7&quot;<\/font>,<font color=\"#ff00ff\">&quot;8&quot;<\/font>,<font color=\"#ff00ff\">&quot;9&quot;<\/font>)\n$keyStartIndex = [<font color=\"#0000ff\">int<\/font>]52;\n$keyEndIndex = [<font color=\"#0000ff\">int<\/font>]($keyStartIndex + 15);\n$decodeLength = [<font color=\"#0000ff\">int<\/font>]29\n$decodeStringLength = [<font color=\"#0000ff\">int<\/font>]15\n$decodedChars = <font color=\"#008080\">new-object<\/font> char[] $decodeLength \n$hexPid = <font color=\"#008080\">new-object<\/font> System.Collections.ArrayList\n<font color=\"#0000ff\">for<\/font> ($i = $keyStartIndex; $i <font color=\"#0000ff\">-le<\/font> $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }\n<font color=\"#0000ff\">for<\/font> ( $i = $decodeLength - 1; $i <font color=\"#0000ff\">-ge<\/font> 0; $i--)\n    {                \n     <font color=\"#0000ff\">if<\/font> (($i + 1) <font color=\"#008080\">%<\/font> 6 <font color=\"#0000ff\">-eq<\/font> 0){$decodedChars[$i] = '&amp;<font color=\"#008000\">#45;'}<\/font>\n     <font color=\"#0000ff\">else<\/font>\n       {\n        $digitMapIndex = [<font color=\"#0000ff\">int<\/font>]0\n        <font color=\"#0000ff\">for<\/font> ($j = $decodeStringLength - 1; $j <font color=\"#0000ff\">-ge<\/font> 0; $j--)\n        {\n            $byteValue = [<font color=\"#0000ff\">int<\/font>](($digitMapIndex * [<font color=\"#0000ff\">int<\/font>]256) <font color=\"#0000ff\">-bor<\/font> [byte]$hexPid[$j]);\n            $hexPid[$j] = [byte] ([math]::Floor($byteValue \/ 24));\n            $digitMapIndex = $byteValue <font color=\"#008080\">%<\/font> 24;\n            $decodedChars[$i] = $lookup[$digitMapIndex];\n         }\n        }\n     }\n$STR = <font color=\"#ff00ff\">''<\/font>     \n$decodedChars | <font color=\"#008080\">%<\/font> { $str+=$_}\n$STR\n}\n\nGet-WindowsProductKey .<\/pre>\n<p>\u6267\u884c\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.fuhaijun.com\/wp-content\/uploads\/2013\/10\/image3.png\" width=\"669\" height=\"134\" \/>&#160;<\/p>\n<p>\u4f5c\u8005: \u4ed8\u6d77\u519b<br \/>\n  <br \/>\u7248\u6743\uff1a\u672c\u6587\u7248\u6743\u5f52\u4f5c\u8005\u6240\u6709 <\/p>\n<p>\u8f6c\u8f7d\uff1a\u6b22\u8fce\u8f6c\u8f7d\uff0c\u4e3a\u4e86\u4fdd\u5b58\u4f5c\u8005\u7684\u521b\u4f5c\u70ed\u60c5\uff0c\u8bf7\u6309\u8981\u6c42\u3010\u8f6c\u8f7d\u3011\uff0c\u8c22\u8c22 <\/p>\n<p>\u8981\u6c42\uff1a\u672a\u7ecf\u4f5c\u8005\u540c\u610f\uff0c\u5fc5\u987b\u4fdd\u7559\u6b64\u6bb5\u58f0\u660e\uff1b\u5fc5\u987b\u5728\u6587\u7ae0\u4e2d\u7ed9\u51fa\u539f\u6587\u8fde\u63a5\u4e14\u4fdd\u8bc1\u5185\u5bb9\u5b8c\u6574!\u5426\u5219\u5fc5\u7a76\u6cd5\u5f8b\u8d23\u4efb! <\/p>\n<p>\u4e2a\u4eba\u7f51\u7ad9: <a href=\"http:\/\/www.fuhaijun.com\/\">http:\/\/www.fuhaijun.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5927\u591a\u6570\u4eba\u53ef\u80fd\u7528\u8fc7VBS\u8bfb\u53d6Windows\u4ea7\u54c1\u5bc6\u94a5\u7684VBS\u811a\u672c\uff0cVBS\u811a\u672c\u901a\u5e38\u90fd\u6bd4\u8f83\u9690\u6666\u3001\u96be\u61c2\uff0c\u4eca\u5929\u5fd9\u91cc\u5077\u95f2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,1],"tags":[],"class_list":["post-33509","post","type-post","status-publish","format-standard","hentry","category-powershell","category-default"],"_links":{"self":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33509"}],"collection":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33509"}],"version-history":[{"count":1,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33509\/revisions"}],"predecessor-version":[{"id":33738,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/33509\/revisions\/33738"}],"wp:attachment":[{"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}