==============
wmi_reg.js
==============var HKCR = 0x80000000; //HKEY_CLASSES_ROOT
var HKCU = 0x80000001; //HKEY_CURRENT_USER
var HKLM = 0x80000002; //HKEY_LOCAL_MACHINE
var HKUS = 0x80000003; //HKEY_USERS
var HKCC = 0x80000005; //HKEY_CURRENT_CONFIGvar HKEY_CLASSES_ROOT = 0x80000000;
var HKEY_CURRENT_USER = 0x80000001;
var HKEY_LOCAL_MACHINE = 0x80000002;
var HKEY_USERS = 0x80000003;
var HKEY_CURRENT_CONFIG = 0x80000005;var REG_SZ = 1;
var REG_EXPAND_SZ = 2;
var REG_BINARY = 3;
var REG_DWORD = 4;
var REG_MULTI_SZ = 7;function WMI(){} //WMI Object//********************************************************
function EnumMethods(MethodName, sRoot, sRegPath)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item(MethodName);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
return oOutParam; //返回输出参数对象
}
function GetMethods(MethodName, sRoot, sRegPath, strValueName)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item(MethodName);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
oInParam.sValueName = strValueName; var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
return oOutParam; //返回输出参数对象
}
function SetMethods(MethodName, sRoot, sRegPath, strValueName, xValue)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item(MethodName);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
oInParam.sValueName = strValueName;
//oInParam.sValue = xValue;
if (typeof(xValue) == "object") {
if(typeof(xValue[0]) == "string") oInParam.sValue = xValue;
else oInParam.uValue = xValue;
} else {
if (typeof(xValue) == "string") oInParam.sValue = xValue;
else oInParam.uValue = xValue;
} var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}
//************************************************//枚举注册表值和类型
WMI.prototype.EnumValues = function(sRoot, sRegPath)
{
var oOutParam = EnumMethods("EnumValues", sRoot, sRegPath); if (oOutParam.sNames!=null){
var o = new Object();
o["Names"] = oOutParam.sNames.toArray();
o["Types"] = oOutParam.Types.toArray();
return o;
} else { return null;}
};//枚举子项
WMI.prototype.EnumKey = function(sRoot, sRegPath)
{
var oOutParam = EnumMethods("EnumKey", sRoot, sRegPath);
if (oOutParam.sNames==null) return null;
else return oOutParam.sNames.toArray();
}//读取字符串
WMI.prototype.GetStringValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetStringValue", sRoot, sRegPath, strValueName);
return oOutParam.sValue; //注意是sValue
}//读取DWORD值
WMI.prototype.GetDWORDValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetDWORDValue", sRoot, sRegPath, strValueName); return oOutParam.uValue; //注意是uValue
}//读取扩展的字符串值
WMI.prototype.GetExpandedStringValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetExpandedStringValue", sRoot, sRegPath, strValueName); return oOutParam.sValue; //注意是sValue
}//读取 MultiString 值
WMI.prototype.GetMultiStringValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetMultiStringValue", sRoot, sRegPath, strValueName); return oOutParam.sValue.toArray();
}//读取二进制注册表值
WMI.prototype.GetBinaryValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetBinaryValue", sRoot, sRegPath, strValueName); return oOutParam.uValue.toArray(); //注意是uValue
}
//创建扩展的字符串值
WMI.prototype.SetExpandedStringValue = function(sRoot, sRegPath, strValueName, strValue)
{
SetMethods("SetExpandedStringValue", sRoot, sRegPath, strValueName, strValue)
}//创建字符串
WMI.prototype.SetStringValue = function(sRoot, sRegPath, strValueName, strValue)
{
SetMethods("SetStringValue", sRoot, sRegPath, strValueName, strValue)
}//创建DWORD值
WMI.prototype.SetDWORDValue = function(sRoot, sRegPath, strValueName, dwValue)
{
SetMethods("SetDWORDValue", sRoot, sRegPath, strValueName, dwValue)
}//创建 MultiString 值
WMI.prototype.SetMultiStringValue = function(sRoot, sRegPath, strValueName, aValue)
{
SetMethods("SetMultiStringValue", sRoot, sRegPath, strValueName, aValue)
}
//创建 MultiString 值
WMI.prototype.SetBinaryValue = function(sRoot, sRegPath, strValueName, aValue)
{
SetMethods("SetBinaryValue", sRoot, sRegPath, strValueName, aValue)
}//创建注册表项
//sRegPath串,可以一次创建完整的项子树(各级不存在也会被创建)
WMI.prototype.CreateKey = function(sRoot, sRegPath)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item("CreateKey");
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath; var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}//删除注册表项
//只能删除叶结点项(如果该项下还有子项则不能删除,无效果)
//删除所指定的但并不存在子项无效果
//删除指定的子项时,连同该子项下的所有值均被删除
WMI.prototype.DeleteKey = function(sRoot, sRegPath)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item("DeleteKey");
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath; var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}//删除注册表值
WMI.prototype.DeleteValue = function(sRoot, sRegPath, strValueName)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item("DeleteValue");
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
oInParam.sValueName = strValueName;
var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}/=========================================\
| =|
| http://blog.csdn.net/donghid =|
| =|
\=========================================/
wmi_reg.js
==============var HKCR = 0x80000000; //HKEY_CLASSES_ROOT
var HKCU = 0x80000001; //HKEY_CURRENT_USER
var HKLM = 0x80000002; //HKEY_LOCAL_MACHINE
var HKUS = 0x80000003; //HKEY_USERS
var HKCC = 0x80000005; //HKEY_CURRENT_CONFIGvar HKEY_CLASSES_ROOT = 0x80000000;
var HKEY_CURRENT_USER = 0x80000001;
var HKEY_LOCAL_MACHINE = 0x80000002;
var HKEY_USERS = 0x80000003;
var HKEY_CURRENT_CONFIG = 0x80000005;var REG_SZ = 1;
var REG_EXPAND_SZ = 2;
var REG_BINARY = 3;
var REG_DWORD = 4;
var REG_MULTI_SZ = 7;function WMI(){} //WMI Object//********************************************************
function EnumMethods(MethodName, sRoot, sRegPath)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item(MethodName);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
return oOutParam; //返回输出参数对象
}
function GetMethods(MethodName, sRoot, sRegPath, strValueName)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item(MethodName);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
oInParam.sValueName = strValueName; var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
return oOutParam; //返回输出参数对象
}
function SetMethods(MethodName, sRoot, sRegPath, strValueName, xValue)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item(MethodName);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
oInParam.sValueName = strValueName;
//oInParam.sValue = xValue;
if (typeof(xValue) == "object") {
if(typeof(xValue[0]) == "string") oInParam.sValue = xValue;
else oInParam.uValue = xValue;
} else {
if (typeof(xValue) == "string") oInParam.sValue = xValue;
else oInParam.uValue = xValue;
} var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}
//************************************************//枚举注册表值和类型
WMI.prototype.EnumValues = function(sRoot, sRegPath)
{
var oOutParam = EnumMethods("EnumValues", sRoot, sRegPath); if (oOutParam.sNames!=null){
var o = new Object();
o["Names"] = oOutParam.sNames.toArray();
o["Types"] = oOutParam.Types.toArray();
return o;
} else { return null;}
};//枚举子项
WMI.prototype.EnumKey = function(sRoot, sRegPath)
{
var oOutParam = EnumMethods("EnumKey", sRoot, sRegPath);
if (oOutParam.sNames==null) return null;
else return oOutParam.sNames.toArray();
}//读取字符串
WMI.prototype.GetStringValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetStringValue", sRoot, sRegPath, strValueName);
return oOutParam.sValue; //注意是sValue
}//读取DWORD值
WMI.prototype.GetDWORDValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetDWORDValue", sRoot, sRegPath, strValueName); return oOutParam.uValue; //注意是uValue
}//读取扩展的字符串值
WMI.prototype.GetExpandedStringValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetExpandedStringValue", sRoot, sRegPath, strValueName); return oOutParam.sValue; //注意是sValue
}//读取 MultiString 值
WMI.prototype.GetMultiStringValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetMultiStringValue", sRoot, sRegPath, strValueName); return oOutParam.sValue.toArray();
}//读取二进制注册表值
WMI.prototype.GetBinaryValue = function(sRoot, sRegPath, strValueName)
{
var oOutParam = GetMethods("GetBinaryValue", sRoot, sRegPath, strValueName); return oOutParam.uValue.toArray(); //注意是uValue
}
//创建扩展的字符串值
WMI.prototype.SetExpandedStringValue = function(sRoot, sRegPath, strValueName, strValue)
{
SetMethods("SetExpandedStringValue", sRoot, sRegPath, strValueName, strValue)
}//创建字符串
WMI.prototype.SetStringValue = function(sRoot, sRegPath, strValueName, strValue)
{
SetMethods("SetStringValue", sRoot, sRegPath, strValueName, strValue)
}//创建DWORD值
WMI.prototype.SetDWORDValue = function(sRoot, sRegPath, strValueName, dwValue)
{
SetMethods("SetDWORDValue", sRoot, sRegPath, strValueName, dwValue)
}//创建 MultiString 值
WMI.prototype.SetMultiStringValue = function(sRoot, sRegPath, strValueName, aValue)
{
SetMethods("SetMultiStringValue", sRoot, sRegPath, strValueName, aValue)
}
//创建 MultiString 值
WMI.prototype.SetBinaryValue = function(sRoot, sRegPath, strValueName, aValue)
{
SetMethods("SetBinaryValue", sRoot, sRegPath, strValueName, aValue)
}//创建注册表项
//sRegPath串,可以一次创建完整的项子树(各级不存在也会被创建)
WMI.prototype.CreateKey = function(sRoot, sRegPath)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item("CreateKey");
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath; var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}//删除注册表项
//只能删除叶结点项(如果该项下还有子项则不能删除,无效果)
//删除所指定的但并不存在子项无效果
//删除指定的子项时,连同该子项下的所有值均被删除
WMI.prototype.DeleteKey = function(sRoot, sRegPath)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item("DeleteKey");
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath; var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}//删除注册表值
WMI.prototype.DeleteValue = function(sRoot, sRegPath, strValueName)
{
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(null, "root\\default");
var oReg = oSvc.Get("StdRegProv"); var oMethod = oReg.Methods_.Item("DeleteValue");
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = sRoot;
oInParam.sSubKeyName = sRegPath;
oInParam.sValueName = strValueName;
var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
}/=========================================\
| =|
| http://blog.csdn.net/donghid =|
| =|
\=========================================/
解决方案 »
- 如何判断在JS中通过表单的submit函数提交是否成功
- jquery如何获取radiobuttonlist选中的显示文本值
- 我像请教一个文本框上下键的问题
- 如何判断RadioButton选中/未选中?
- js操作frameset的问题
- 各位大哥哥,进来帮帮我好吗?
- 请问如何获取本页table ID为ttt的所有table并修改class???
- 正则式为什么这么痛苦?如此简单的,都不行,大家来看看吧!
- 我用js+vml编写几个函数,功能倒是实现了,却遇到几个问题!!!,高手帮忙!!
- 我想实现这样的效果:当我选下拉菜单里的某一 向时,在其下面出现相关的项目。。。。
- 为iframe设置焦点的问题
- 初学者提问
Sh = new ActiveXObject("WScript.Shell");
Sh.RegWrite
Sh.RegRead
比较方便