REG.HTA
==========================================
<html>
<head>
<title>用WMI操作注册表</title>
<STYLE type="text/css">
#lArea {
float:left;
}
#lArea DIV {
margin:5px;
}
#rArea {
float:left;
width:300px;
height:400px;
overflow:auto;
border:1px outset #FFFFEE;
font-size:10pt;
}
</STYLE>
<SCRIPT SRC="wmi_reg.js"></SCRIPT>
<SCRIPT>
function ClearURLs()
{
var sKeyPath = "Software//Microsoft//Internet Explorer//TypedURLs";
var oReg = new WMI();
var oKeys = oReg.EnumValues(HKCU, sKeyPath);
if(oKeys!=null){
var aNames = oKeys.Names;
for(var i=0; i<aNames.length; i++)
oReg.DeleteValue(HKCU, sKeyPath, aNames[i]);
}
}
function SetValue(index, dwValue)
{
var o = oList[index];
//alert(o.sKeyPath);
oReg.CreateKey(o.root, o.sKeyPath);
oReg.SetDWORDValue(o.root, o.sKeyPath, o.sValueName, dwValue);
}
function OBJ(Root, sKeyPath, sValueName, Description)
{
this.root = Root;
this.sKeyPath = sKeyPath;
this.sValueName = sValueName;
this.des = Description;
}
var oList = new Array(
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//ActiveDesktop", "NoChangingWallPaper", "禁止更改桌面壁纸"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//System", "DisableTaskMgr", "禁用任务管理器"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//System", "DisableRegistryTools", "禁用注册表编辑器"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoBandCustomize", "禁用自定义工具栏"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoSetTaskbar", "禁止修改Taskbar和Start菜单的设置"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoDesktop", "隐藏桌面"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoSaveSettings", "不保存设置"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoRecentDocsMenu", "取消〖文档〗菜单"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoFavoritesMenu", "取消“〖收藏夹〗”菜单项"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoRun", "取消“〖运行〗”菜单项"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoViewContextMenu", "禁在桌面用上右键"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoTrayContextMenu", "禁止任务栏属性菜单"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoThumbnailCache", "禁用缓存缩略图"),
new OBJ(HKCU, "Software//Policies//Microsoft//Internet Explorer//Control Panel", "HomePage", "禁止更改主页设置"),
new OBJ(HKCU, "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer", "NoChangeStartMenu", "禁止拖放更改开始菜单中项")
)
var oReg = new WMI();
function Check(t)
{
if(t.checked) SetValue(parseInt(t.value), 1);
else SetValue(parseInt(t.value), 0);
}
function preCheck()
{
var str = '<form name="theForm">';
for(var i=0; i<oList.length; i++){
var dwValue = oReg.GetDWORDValue(oList[i].root, oList[i].sKeyPath, oList[i].sValueName);
if (dwValue != 0 && dwValue !=null) str +='<DIV><INPUT type="checkbox" checked onClick="Check(this)" value=' + i + '>' + oList[i].des + '</DIV>';
else str +='<DIV><INPUT type="checkbox" onClick="Check(this)" value=' + i + '>' + oList[i].des + '</DIV>';
}
str += '</form>';
disp.innerHTML = str;
}
</SCRIPT>
</head>
<body>
<DIV>
<DIV id="lArea">
<DIV><BUTTON onClick="ClearURLs()">清除地址栏</BUTTON></DIV>
<DIV><BUTTON onClick="preCheck()"> 系统功能 </BUTTON></DIV>
</DIV>
<DIV id="rArea">
<DIV id="disp"></DIV>
</DIV>
</DIV>
</body>
</html>
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_CONFIG
var 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);
}