Created
June 30, 2009 09:36
-
-
Save tckz/138093 to your computer and use it in GitHub Desktop.
jscriptでレジストリ参照(リモート可)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Registry = function () { | |
this.initialize.apply(this, arguments); | |
}; | |
Registry.prototype = { | |
initialize: function(computer) { | |
var locator = new ActiveXObject("WbemScripting.SWbemLocator"); | |
var server = locator.ConnectServer(computer, "root\\default"); | |
this.stdregprov = server.Get("StdRegProv"); | |
this.HKCR = 0x80000000; // HKEY_CLASSES_ROOT | |
this.HKCU = 0x80000001; // HKEY_CURRENT_USER | |
this.HKLM = 0x80000002; // HKEY_LOCAL_MACHINE | |
this.HKUS = 0x80000003; // HKEY_USERS | |
this.HKCC = 0x80000005; // HKEY_CURRENT_CONFIG | |
this.REG_SZ = 1; | |
this.REG_EXPAND_SZ = 2; | |
this.REG_BINARY = 3; | |
this.REG_DWORD = 4; | |
this.REG_MULTI_SZ = 7; | |
}, | |
do_method: function(method_name, hkey, key, value_name) { | |
var in_param = this.stdregprov.Methods_.Item(method_name).InParameters.SpawnInstance_(); | |
in_param.hDefKey = hkey; | |
in_param.sSubKeyName = key; | |
if(value_name != null) | |
{ | |
in_param.sValueName = value_name; | |
} | |
var out = this.stdregprov.ExecMethod_(method_name, in_param); | |
return out; | |
}, | |
EnumKey: function(hkey, key) { | |
var out_param = this.do_method("EnumKey", hkey, key); | |
var names = []; | |
if(out_param.sNames != null) | |
{ | |
names = out_param.sNames.toArray(); | |
} | |
return names; | |
}, | |
EnumValues: function(hkey, key) { | |
var out_param = this.do_method("EnumValues", hkey, key); | |
var value_names = []; | |
if(out_param.sNames != null) | |
{ | |
value_names = out_param.sNames.toArray(); | |
} | |
var value_types = []; | |
if(out_param.Types != null) | |
{ | |
value_types = out_param.Types.toArray(); | |
} | |
return { | |
Names: value_names, | |
Types: value_types | |
}; | |
}, | |
GetStringValue: function(hkey, key, name) { | |
// REG_SZ | |
var out_param = this.do_method("GetStringValue", hkey, key, name); | |
// 値が存在しない場合null | |
return out_param.sValue; | |
}, | |
GetExpandedStringValue: function(hkey, key, name) { | |
// REG_EXPAND_SZ | |
var out_param = this.do_method("GetExpandedStringValue", hkey, key, name); | |
// 値が存在しない場合null | |
return out_param.sValue; | |
}, | |
GetDWORDValue: function(hkey, key, name) { | |
// REG_DWORD | |
var out_param = this.do_method("GetDWORDValue", hkey, key, name); | |
// 値が存在しない場合null | |
return out_param.uValue; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment