上学时用javascript 和 html 写的小程序,尘封了太久了拿出来亮亮 希望对人有帮助. 拷贝html代码然后保存为DriMgr.hta 双击便可运行,不过只能在win平台上 ,不知XChiunx 允许发非Qt的帖子否 , 如果不可 , 劳烦通知我一下 .
<html>
<hta:application
icon="C:\windows\system32\mmc.exe"
windowstate="maximize"
scroll="no"
border="none"
>
<head>
<style type="text/css">
body{background:black}
#DriverListBox{background:black;color:green;width:500}
#DriverInfoField{position:absolute;top:90;left:550}
#DriverInfoTextarea{position:relative;top:0}
#InfoDetail{background:black;color:green}
.Btn{width:80}
#board{color:green}
</style>
<script language="javascript">
var objWMIService=GetObject("winmgmts:\\\\.\\root\\cimv2");
var strHTML="";
var FSO=new ActiveXObject("Scripting.filesystemobjecT");
var SHELL=new ActiveXObject("Wscript.shell");
function LoadAllDrivers(){
//alert("LoadRunningDrivers");
strHTML="";
strHTML+="<select id='DriverListBox' size=35 multiple onchange='RetrieveDriverInfo(this)' ondblclick='LocateDriverFile(DriverPath(this))'>";
var oDrivers=new Enumerator(objWMIService.execquery("select * from win32_systemdriver"))
while(!oDrivers.atEnd()){
//alert("one");
var Driver=oDrivers.item();
strHTML+="<option>"+Driver.caption+"</option>";
oDrivers.moveNext();
}
strHTML+="</select>";
document.getElementById('DriverField').innerHTML=strHTML;
}
function LoadFilteredDriversByState(ListBox){
strHTML="";
var State=new String(ListBox.options[ListBox.selectedIndex].text);
strHTML+="<select id='DriverListBox' size=35 multiple onchange='RetrieveDriverInfo(this)' ondblclick='LocateDriverFile(DriverPath(this))'>";
if(State.toLowerCase()=="all"){
LoadAllDrivers();
return true;
}
var oDrivers=new Enumerator(objWMIService.execquery("select * from win32_systemdriver where state='"+State+"'"));
while(!oDrivers.atEnd()){
//alert("one");
var Driver=oDrivers.item();
strHTML+="<option>"+Driver.caption+"</option>";
oDrivers.moveNext();
}
strHTML+="</select>";
document.getElementById('DriverField').innerHTML=strHTML;
}
function LoadFilteredDriversByStartMode(ListBox){
strHTML="";
var StartMode=new String(ListBox.options[ListBox.selectedIndex].text);
strHTML+="<select id='DriverListBox' size=35 multiple onchange='RetrieveDriverInfo(this)' ondblclick='LocateDriverFile(DriverPath(this))'>";
var oDrivers=new Enumerator(objWMIService.execquery("select * from win32_systemdriver where startmode='"+StartMode+"'"));
while(!oDrivers.atEnd()){
//alert("one");
var Driver=oDrivers.item();
strHTML+="<option>"+Driver.caption+"</option>";
oDrivers.moveNext();
}
strHTML+="</select>";
document.getElementById('DriverField').innerHTML=strHTML;
}
function RetrieveDriverInfo(ListBox){
//alert("RetrieveDriverInfo");
strHTML="";
var DriverCaption=ListBox.options[ListBox.selectedIndex].text;
var oDrivers=new Enumerator(objWMIService.execquery("select * from win32_systemdriver where caption='"+DriverCaption+"'"));
strHTML="<fieldset id='InfoDetail'><legend>Driver Info</legend>";
while(!oDrivers.atEnd()){
var Driver=oDrivers.item();
strHTML+="AcceptPause: " + Driver.AcceptPause+"<br>";
strHTML+="AcceptStop: " + Driver.AcceptStop+"<br>";
strHTML+="Caption: " + Driver.Caption+"<br>";
strHTML+="CreationClassName: " + Driver.CreationClassName+"<br>";
strHTML+="Description: " + Driver.Description+"<br>";
strHTML+="DesktopInteract: " + Driver.DesktopInteract+"<br>";
strHTML+="DisplayName: " + Driver.DisplayName+"<br>";
strHTML+="ErrorControl: " + Driver.ErrorControl+"<br>";
strHTML+="ExitCode: " + Driver.ExitCode+"<br>";
strHTML+="Name: " + Driver.Name+"<br>";
strHTML+="PathName: " + Driver.PathName+"<br>";
strHTML+="ServiceSpecificExitCode: " + Driver.ServiceSpecificExitCode+"<br>";
strHTML+="ServiceType: " + Driver.ServiceType+"<br>";
strHTML+="Started: " + Driver.Started+"<br>";
strHTML+="StartMode: " + Driver.StartMode+"<br>";
strHTML+="StartName: " + Driver.StartName+"<br>";
strHTML+="State: " + Driver.State+"<br>";
strHTML+="Status: " + Driver.Status+"<br>";
strHTML+="SystemCreationClassName: " + Driver.SystemCreationClassName+"<br>";
strHTML+="SystemName: " + Driver.SystemName+"<br>";
strHTML+="TagId: " + Driver.TagId+"<br>";
oDrivers.moveNext();
}
strHTML+="</fieldset>"
document.getElementById('DriverInfoField').innerHTML=strHTML;
}
function LocateDriverFile(Path){
if(Path=="N/A"){
return false;
}
try{
StripOffFileProperties(Path);
SHELL.Run("Explorer /select,"+Path);
}catch(e){
alert(e.message);
}
}
function DriverPath(ListBox){
var Caption=ListBox.options[ListBox.selectedIndex].text;
var oDrivers=new Enumerator(objWMIService.execquery("Select pathname from win32_systemdriver where caption='"+Caption+"'"));
while(!oDrivers.atEnd()){
var Driver=oDrivers.item();
var PathName=Driver.pathname;
oDrivers.moveNext();
}
if(PathName==null){
return "N/A";
}else{
return PathName;
}
}
function StripOffFileProperties(Path){
FSO.GetFile(Path).Attributes=0;
}
function DeleteDriver(){
var index=DriverListBox.selectedIndex;
if(index<0){
alert("no selected driver!");
return false;
}
if(!confirm("Are you sure?")){
alert("Operation aborted !");
return false;
}
var Caption=DriverListBox.options[DriverListBox.selectedIndex].text;
return true;
try {
var objOutParams = objWMIService.ExecMethod("Win32_SystemDriver.Name='"+Caption+"'", "Delete")
}catch(e){alert(e.message);}
}
function SetDriverStartupMode(ListBox){
if(DriverListBox.selectedIndex<0){
alert("no selected driver!");
return false;
}
var Caption=DriverListBox.options[DriverListBox.selectedIndex].text;
var StartupMode=ListBox.options[ListBox.selectedIndex].text;
var objShare = objWMIService.Get("Win32_SystemDriver.Name='"+Caption+"'");
//Obtain an InParameters object specific
//to the method.
var objInParam = objShare.Methods_("ChangeStartMode").inParameters.SpawnInstance_();
//Add the input parameters.
objInParam.Properties_.Item("StartMode") =StartupMode;
//Execute the method and obtain the return status.
//The OutParameters object in objOutParams
//is created by the provider.
try {
var objOutParams = objWMIService.ExecMethod("Win32_SystemDriver.Name='"+Caption+"'", "ChangeStartMode", objInParam);
}catch(e){alert(e.message);}
}
function StopDriver(){
var index=DriverListBox.selectedIndex;
if(index<0){
alert("no selected driver!");
return false;
}
if(!confirm("Are you sure?")){
alert("Operation aborted !");
return false;
}
var Caption=DriverListBox.options[DriverListBox.selectedIndex].text;
return true;
try {
var objOutParams = objWMIService.ExecMethod("Win32_SystemDriver.Name='"+Caption+"'", "StopService")
}catch(e){alert(e.message);}
}
function StartDriver(){
var index=DriverListBox.selectedIndex;
if(index<0){
alert("no selected driver!");
return false;
}
if(!confirm("Are you sure?")){
alert("Operation aborted !");
return false;
}
var Caption=DriverListBox.options[DriverListBox.selectedIndex].text;
return true;
try {
var objOutParams = objWMIService.ExecMethod("Win32_SystemDriver.Name='"+Caption+"'", "StartService")
}catch(e){alert(e.message);}
}
</script>
<title>Driver Manager</title>
</head>
<body onload="LoadAllDrivers()">
<fieldset id="Board">
<legend>Manipulation</legend>
<center><select id="StartModeListBox" class="listbox" onchange="LoadFilteredDriversByStartMode(this)">
<option>StartMode</option>
<option>Auto</option>
<option>Manual</option>
<option>Disabled</option>
<option>System</option>
</select> <select id="StatusListBox" class="listbox" onchange="LoadFilteredDriversByState(this)">
<option>State</option>
<option>ALL</option>
<option>Running</option>
<option>Stopped</option>
</select> <select id="SetupListBox" class="listbox" onchange="SetDriverStartupMode(this)">
<option>Set</option>
<option>Auto</option>
<option>Disabled</option>
<option>Manual</option>
</select> <input type="button" value="Stop" class="btn" onclick="StopDriver()"> <input type="button" value="Start" class="btn" onclick="StartDriver()"> <input type="button" value="Delete" class="btn" onclick="DeleteDriver()">
</center>
</fieldset>
<hr>
<pre>
<span id="DriverField"></span> <span id="DriverInfoField"></span>
</pre>
</body>
</html>