先のWindowsのライセンス取得をJScript.netで書き直してみたバージョン。
こっちはコンパイルしてEXEにしたりDLLにして使い回すことも可能。
レジストリのキー値がすべてなんだけどね。
import System; import Microsoft.Win32; import System.Windows.Forms; class ProductKey{ public office_regkeys = { // 参考 http://d.hatena.ne.jp/frontline/20081222/p1 "Office XP Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\10.0\\Registration\\{90280411-6000-11D3-8CFE-0050048383C9}", "Office XP Professional(English)":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\10.0\\Registration\\{90110409-6000-11D3-8CFE-0050048383C9}", "Office 2003 Standard/Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\11.0\\Registration\\{90110411-6000-11D3-8CFE-0150048383C9}", "Visio 2003 Standard/Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\11.0\\Registration\\{90510411-6000-11D3-8CFE-0150048383C9}", "Office 2007 Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0014-0000-0000-0000000FF1CE}", "Office 2007 Professional Plus":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0011-0000-0000-0000000FF1CE}", "Office 2007 Enterprise":"HKEY_LOCAL_MACHINE\\SOFTWAWRE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0030-0000-0000-0000000FF1CE}", "Office 2007 Ultimate":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{91120000-002E-0000-0000-0000000FF1CE}", "Visio 2007 Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0051-0000-0000-0000000FF1CE}", "Project 2007 Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-003B-0000-0000-0000000FF1CE}", "SQL Server 2005":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\90\\ProductID" }; public function ProductKey(){ //コンストラクタ } public function windows(){ var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion") var DigitalProductId = key.GetValue("DigitalProductId"); var hexPid = DigitalProductId.slice( 52, 67 ); return this.decode(hexPid); //return ret; } public function office(){ var result = []; for ( key_name in this.office_regkeys ){ try{ var ret = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion") var ret = this.read_reg(this.office_regkeys[key_name]+ '\\DigitalProductId'); result.push( key_name + ":\t" + this.decodeDigitalProductId( ret )); }catch(e){ // } } return result.join("\n"); } public function decode( binary_regkey ){ var decodedChars = Array(24); var digits = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"); for ( var i=1; i<30;i++ ){ if((i % 6) == 0 ){ decodedChars.push("-"); } else{ var k=0; for ( var j=14; j>=0;j--){ k = ( k << 8 ) ^ binary_regkey[j]; binary_regkey[j] = parseInt( k /digits.length ); k = k % digits.length; } decodedChars.push(digits[k]); } } return (decodedChars.reverse().join("")); } } //メイン var p = new ProductKey();