日期:2014-05-16  浏览次数:20384 次

经典常用javaScript技术代码
经常用到的javaScript技术代码(经典)

//取得网络上的打印机
function getnetprinter()
{powered by 25175.net
  var obj=new ActiveXObject("WScript.network");
  var netprinter=obj.EnumPrinterConnections(); 
  for(i=0;i<netprinter.Count();i+=2)
  {
    document.writeln(netprinter.Item(i)+"="+netprinter.Item(i+1));
  }
}
//取得磁盘信息 传入参数如:getdiskinfo('c')
function getdiskinfo(para)
{
  var fs=new ActiveXObject("scripting.filesystemobject");
  d=fs.GetDrive(para);
  s="卷标:" + d.VolumnName;
  s+="------" + "剩余空间:" + d.FreeSpace/1024/1024 + "M";
  s+="------" + "磁盘序列号:" + d.serialnumber;
  alert(s)
}
//取得系统目录
function getprocessnum()
{
    var pnsys=new ActiveXObject("WScript.shell");
    pn=pnsys.Environment("PROCESS");
    alert(pn("WINDIR"));
}
//启动计算器
function runcalc()
{
  var calc=new ActiveXObject("WScript.shell");
  calc.Run("calc");
}
//读取注册表中的值
function readreg()
{
  var myreadreg=new ActiveXObject("WScript.shell");
  try{
    alert(myreadreg.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\NeroCheck"));
  }
  catch(e)
  {
    alert("读取的值不存在!");
  }
}
//写注册表
function writereg()
{
  var mywritereg=new ActiveXObject("WScript.shell");
  try{
    mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
    alert("写入成功!");
  }
  catch(e)
  {
    alert("写入路径不正确!");
  }
}
//删除注册表
function delreg()
{
  var mydelreg=new ActiveXObject("WScript.shell");
  if(confirm("是否真的删除?"))
  {
    try{
   mydelreg.Regdelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest");
   alert("删除成功!");
}
catch(e)
{
   alert("删除路径不正确");
}
  }
}
//取得计算机名域名用户名
function netinfo()
{
  var mynetinfo=new ActiveXObject("WScript.network");
  alert("计算机名:"+mynetinfo.ComputerName+"域名:"+mynetinfo.UserDomain+"用户名:"+mynetinfo.UserName);
}
//返回系统中特殊目录的路径 (Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
  var mygetfolder=new ActiveXObject("WScript.shell");
  if(mygetfolder.SpecialFolders("Fonts")!=null)
  {
    alert(mygetfolder.SpecialFolders("Fonts"));
  }
}
//取得文件信息  调用方式如:getfileinfo('E:\\MyPlace\\TEST\\myjs.htm')
function getfileinfo(para)
{
  var myfile=new ActiveXObject("scripting.filesystemobject");
  var fi=myfile.GetFile(para);
  alert("文件类型:"+fi.type+"文件大小:"+fi.size/1024/1024+"M"+"最后一次访问时间:"+fi.DateLastAccessed);
}
//取得客户端的信息
function clientInfo()
{
  strClientInfo="availHeight=   "+window.screen.availHeight+"\n"+
    "availWidth=   "+window.screen.availWidth+"\n"+
    "bufferDepth=   "+window.screen.bufferDepth+"\n"+
    "colorDepth=   "+window.screen.colorDepth+"\n"+
    "colorEnable=   "+window.navigator.cookieEnabled+"\n"+
    "cpuClass=   "+window.navigator.cpuClass+"\n"+
    "height=   "+window.screen.height+"\n"+
    "javaEnable=   "+window.navigator.javaEnabled()+"\n"+
 &nbs