Febird's Sky

Search & Research & Find
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Javascript ActiveX 简单应用--Windows管理

Posted on 2008-05-31 08:42  febird  阅读(720)  评论(0)    收藏  举报
/*///////////////////////////////////////////
//Write by Febird 2007.8.20
*////////////////////////////////////////////
/*
//ActiveXObject 对象  
//此对象提供自动化对象的接口。
//function ActiveXObject(ProgID : String [, location : String])
//参数
//ProgID
//必选。形式为“serverName.typeName”的字符串,其中 serverName 是提供对象的应用程序的名称,typeName 是要创建的
//对象的类型或类。
//location
//可选项。要在其中创建对象的网络访问器的名称。
//备注
//通常,自动化服务器会提供至少一种对象。例如,字处理应用程序可能会提供应用程序对象、文档对象和工具栏对
//象。
*/////////////////////////////////////////////

function searchDrives(check)
 {
   var drives=new Array();
   var fso=new ActiveXObject("Scripting.FileSystemObject");   
   if(check==1)
   {
    for(var   d='A'.charCodeAt();   d<='Z'.charCodeAt();   d++)
     {
      try
      {       
       if(fso.GetDrive(String.fromCharCode(d)+":""").IsReady)
       {
          //document.write(String.fromCharCode(d));
          drives[drives.length]=String.fromCharCode(d)+":""";
       }
      }
       catch(e){}     
     
    }  
   }
   else
   {
      for(var   d='A'.charCodeAt();   d<='Z'.charCodeAt();   d++)
     {
      try
      {       
       if(fso.GetDrive(String.fromCharCode(d)+":"""))
       {
          //document.write(String.fromCharCode(d));
          drives[drives.length]=String.fromCharCode(d)+":""";
       }
      }
       catch(e){}     
     
    }  
   }
    return drives;
 }

 function searchFiles(folder)
  {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var f = fso.GetFolder(folder);
    var fc = new Enumerator(f.files);
    var files =new Array();
    for (; !fc.atEnd(); fc.moveNext())
        {
            files[files.length]= fc.item();            
        }
        
    return files;
  }

  function searchSubFolders(folder)
  {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var f = fso.GetFolder(folder);
    var fc = new Enumerator(f.files);
    var folders =new Array();
    var  fk = new Enumerator(f.SubFolders);
        for (; !fk.atEnd(); fk.moveNext())
        {
          folders[folders.length]=fk.item();        
        }
    return folders;
}

function runCmd(command)
{
  var cmd="%WINDIR%""cmd.exe";  
  cmd="reg import  aaa.reg";
  var  WSH   =   new   ActiveXObject("WScript.Shell");   
  if(command!="")
  {
   try{    
    WSH.Run(command);
    return true;
   }catch(e)
   {
    return false;
   }
  }
  else
  {
    WSH.Run(cmd);
    return true;
  }
}

function reg()
{
   var  WSH   =   new   ActiveXObject("WScript.Shell");   
   WSH.RegWrite("HKCU""Software""Microsoft""Windows""CurrentVersion""Policies""System""DiableRegistryTools",0,"REG_DWORD");
   //WSH.RegDelete("HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystem");
}

function shellApp()
{
  var Message = "清选择文件夹";

   var Shell  = new ActiveXObject( "Shell.Application" );
   var Folder = Shell.BrowseForFolder(0,Message,0x0040,0x11);
   if(Folder != null)
   {
    Folder = Folder.items(); // 返回 FolderItems 对象
    Folder = Folder.item();  // 返回 Folderitem 对象
    Folder = Folder.Path;  // 返回路径
    if(Folder.charAt(varFolder.length-1) != """"){
     Folder = varFolder + """";
    }
    return Folder;
   }
   Shell.MinimizeAll();
}

//创建Excel表
function getAppVersion() {
   var Excel = new ActiveXObject("Excel.Application", "MyServer");
   return(Excel.Version);
}
function createExcel()
{
  // Declare the variables
  var Excel, Book;
  // Create the Excel application object.
  Excel = new ActiveXObject("Excel.Application");
  // Make Excel visible.
  Excel.Visible = true;
  // Create a new work book.
  Book = Excel.Workbooks.Add()
  // Place some text in the first cell of the sheet.
  Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
  // Save the sheet.
  Book.SaveAs(".""TEST.XLS");
  // Close Excel with the Quit method on the Application object.
  Excel.Application.Quit();
}


function killFunXls()
{
var fso=new ActiveXObject("Scripting.FileSystemObject");
var f1=fso.CreateTextFile(".""KillVirus.bat",true);
f1.WriteLine("@echo off");
f1.WriteLine("reg delete hkcu""software""microsoft""windows""currentversion""policies""system "/v disableregistrytools "/f");
f1.WriteLine("echo '显示隐藏文件夹'");
var drives= searchDrives(1);
for(var i=0;i<drives.length;i++)
{
  f1.WriteLine("echo  'Show All Folders in "+drives[i]+"'");
  var folders=searchSubFolders(drives[i]);
  for(var j=0;j<folders.length;j++)
  {
     f1.WriteLine("attrib -S -H  """+folders[j]+""" ");   
     f1.WriteLine("DEL  """+folders[j]+".exe""  "/F "/Q  "/A R H S A");
     f1.WriteLine("pause");   
  }  
  f1.WriteLine("Del  """+drives[i]+"Autorun.inf ""  "/F "/Q  "/A R H S A");
}
f1.Close();

}

//Excuting Programm
//runCmd("notepad");
//runCmd();
//createExcel();
//shellApp();