Skip to content

Instantly share code, notes, and snippets.

@takuya

takuya/prod.html

Created Nov 23, 2018
Embed
What would you like to do?
<html><head>
<title>WindowsとOfficeのライセンス確認</title></head>
<body>
<form name="form1">
<p><input type="button" value="Windowsのライセンスを調査" onClick="show_license('')" /></p>
</form>
<div id="result"></div>
<script type="text/javascript">
//by takuya mori 2009-03-26
//Windowsのシリアルを取得する。
function windows_productkey(){
WshShell = new ActiveXObject( "WScript.Shell" );
//ret = WshShell.RegRead('HKCU\\Software\\Microsoft\\Internet Explorer\\Main\\Start Page');
ret = WshShell.RegRead('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId');
DigitalProductId = ret.toArray();
hexPid = DigitalProductId.slice( 52, 67 );
decodedChars = Array(24);
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{
k=0;
for ( var j=14; j>=0;j--){
k = ( k << 8 ) ^ hexPid[j];
hexPid[j] = parseInt( k /digits.length );
k = k % digits.length;
}
decodedChars.push(digits[k]);
}
}
WScript.Echo(decodedChars.reverse().join(""));
}
///windows_productkey関数をオブジェクト化して、Officeにも対応させたもの
var ProductKey = function ( ) {
this.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 VL":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0012-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"
}
this.WshShell = new ActiveXObject( "WScript.Shell" );
this.read_reg = function ( reg_key_name ){
return this.WshShell.RegRead(reg_key_name);
}
this.decodeDigitalProductId = function( reg_binary_value ){
reg_binary_value=reg_binary_value.toArray();
reg_binary_value=reg_binary_value.slice( 52, 67 );
decodedChars = Array(24);
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{
k=0;
for ( var j=14; j>=0;j--){
k = ( k << 8 ) ^ reg_binary_value[j];
reg_binary_value[j] = parseInt( k /digits.length );
k = k % digits.length;
}
decodedChars.push(digits[k]);
}
}
var aa = decodedChars.reverse().join('').split("-")
aa.pop();
aa.push("*****")
return aa.join("-");
}
this.office = function(){
var result = [];
for ( key_name in this.office_regkeys ){
try{
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");
}
this.windows = function (){
return this.WindowsName() + ":\t" + this.Windows_ProductKey();
}
this.Windows_ProductKey = function (){
var ret = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId');
return this.decodeDigitalProductId( ret );
}
this.WindowsName = function(){
var name = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName');
var pack = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\CSDVersion');
return name + "("+pack+")";
}
}
//動作テスト
//windows_productkey()
//var p = new ProductKey();
//WScript.Echo(p.windows());
//WScript.Echo(p.office());
function show_license(){
var p = new ProductKey();
var html = "<ul><li>"+p.windows()+"<li>" + p.office().replace("\n", "<br/>\n<li>") + "</ul>";
document.getElementById("result").innerHTML = html;
}
function send_result(){
var p = new ProductKey();
var oSkype = new ActiveXObject("Skype4COM.Skype");
oSkype.Attach();
oSkype.SendMessage("takuya541226", "\n"+p.windows()+"\n" + p.office());
}
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.