[分享]JS+WMI操作注册表
使用JS+WMI操作注册表,但是执行效率非常成问题。
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>