Posted on 2006-08-25 11:23
花 閱讀(391)
評(píng)論(0) 編輯 收藏 所屬分類:
WEB Design
//取得網(wǎng)絡(luò)上的打印機(jī)
function getnetprinter()
{
? 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));
? }
}
//取得磁盤信息 傳入?yún)?shù)如:getdiskinfo('c')
function getdiskinfo(para)
{
? var fs=new ActiveXObject("scripting.filesystemobject");
? d=fs.GetDrive(para);
? s="卷標(biāo):" + d.VolumnName;
? s+="------" + "剩余空間:" + d.FreeSpace/1024/1024 + "M";
? s+="------" + "磁盤序列號(hào):" + d.serialnumber;
? alert(s)
}
//取得系統(tǒng)目錄
function getprocessnum()
{
??? var pnsys=new ActiveXObject("WScript.shell");
??? pn=pnsys.Environment("PROCESS");
??? alert(pn("WINDIR"));
}
//啟動(dòng)計(jì)算器
function runcalc()
{
? var calc=new ActiveXObject("WScript.shell");
? calc.Run("calc");
}
//讀取注冊(cè)表中的值
function readreg()
{
? var myreadreg=new ActiveXObject("WScript.shell");
? try{
??? alert(myreadreg.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\NeroCheck"));
? }
? catch(e)
? {
??? alert("讀取的值不存在!");
? }
}
//寫注冊(cè)表
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("寫入路徑不正確!");
? }
}
//刪除注冊(cè)表
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("刪除路徑不正確");
?}
? }
}
//取得計(jì)算機(jī)名域名用戶名
function netinfo()
{
? var mynetinfo=new ActiveXObject("WScript.network");
? alert("計(jì)算機(jī)名:"+mynetinfo.ComputerName+"域名:"+mynetinfo.UserDomain+"用戶名:"+mynetinfo.UserName);
}
//返回系統(tǒng)中特殊目錄的路徑 (Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
? var mygetfolder=new ActiveXObject("WScript.shell");
? if(mygetfolder.SpecialFolders("Fonts")!=null)
? {
??? alert(mygetfolder.SpecialFolders("Fonts"));
? }
}
//取得文件信息? 調(diào)用方式如: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"+"最后一次訪問時(shí)間:"+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"+
??? "platform=?? "+window.navigator.platform+"\n"+
??? "systemLanguage=?? "+window.navigator.systemLanguage+"\n"+
??? "userLanguage=?? "+window.navigator.userLanguage+"\n"+
??? "width=?? "+window.screen.width;
? alert(strClientInfo);?
}
//Dilog Helper對(duì)象的使用
function changeColor()//Dilog Helper對(duì)象的使用之調(diào)用系統(tǒng)調(diào)色板
{
var sColor=dlgHelper.choosecolordlg();
sColor=sColor.toString(16);
if (sColor.length < 6) {
? var sTempString = "000000".substring(0,6-sColor.length);
? sColor = sTempString.concat(sColor);
}
alert(sColor);
mybody.style.backgroundColor=sColor;
}
function getFonts()//Dilog Helper對(duì)象的使用之取得系統(tǒng)支持的字體
{
? var strFonts="";
? for(var i=1;i<dlgHelper.fonts.count;i++)
? {
??? strFonts=strFonts+dlgHelper.fonts(i)+"|";
? }
? alert(strFonts);
}
function getBlockFormat()//Dilog Helper對(duì)象的使用之取得系統(tǒng)中塊的格式信息(如:標(biāo)題1、標(biāo)題2....)
{
? var strBlockFormat="";
? for(var i=1;i<dlgHelper.BlockFormats.count;i++)
? {
??? strBlockFormat=strBlockFormat+dlgHelper.BlockFormats(i)+"|";
? }
? alert(strBlockFormat);
}
function createTxtLink()//給選中的文本創(chuàng)建鏈接
{
? var sText=document.selection.createRange();
? if(sText.text!="")
? {
??? document.execCommand("CreateLink");
??? if(sText.parentElement().tagName=="A")
??? {
????? sText.parentElement().innerText=sText.parentElement().href;
????? document.execCommand("ForeColor",false,"#ffff00");
??? }
? }
}
//以下為取得BlockFormats,填充Select(id為myselect)并根據(jù)選擇不同的BlockFormat改變樣式
//函數(shù)fillselect()和changeformat()
//對(duì)execCommand的一點(diǎn)說明:Executes a command over the given selection or text range
function fillselect()
{
? var item=document.createElement("OPTION")
? item.text="請(qǐng)選擇";
? item.value="";
? myselect.add(item);
? for(var i=1;i<dlgHelper.BlockFormats.count;i++)
? {
??? item=document.createElement("OPTION");
??? item.text=dlgHelper.BlockFormats(i);
??? item.value=dlgHelper.BlockFormats(i);
??? myselect.add(item);
? }
}
function changeformat()
{
? var sSelect=myselect.options[myselect.selectedIndex].value;
? document.execCommand("FormatBlock",false,sSelect);
}
//取得驅(qū)動(dòng)器類型,調(diào)用如:ShowDriveType('c:')
function ShowDriveType(drvpath)
{
? fs=new ActiveXObject("scripting.filesystemobject");
? disk=fs.GetDrive(drvpath);
? var whichtype="";
? switch(disk.DriveType)
? {
?case 0:
?? whichtype="Unknown"
?? break
?case 1:
?? whichtype="Removable"
?? break
?case 2:
?? whichtype="Fixed"
?? break
?case 3:
?? whichtype="Network"
?? break
?case 4:
?? whichtype="CD-ROM"
?? break
?case 5:
?? whichtype="RAM Disk"
? }
? alert(whichtype);
? //顯示磁盤的SerialNumber
? try{
?alert(disk.SerialNumber);
? }
? catch(e){
??? alert(e.message);
? }
? alert(disk.VolumeName);//取得卷標(biāo)
}
</script>
-------------------------
<OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>