Javascript 經典自定義函數(轉)

//取得網絡上的打印機
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));
}
}
//取得磁盤信息 傳入參數如: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"+
"platform= "+window.navigator.platform+"\n"+
"systemLanguage= "+window.navigator.systemLanguage+"\n"+
"userLanguage= "+window.navigator.userLanguage+"\n"+
"width= "+window.screen.width;
alert(strClientInfo);
}
//Dilog Helper對象的使用
function changeColor()//Dilog Helper對象的使用之調用系統調色板
{
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對象的使用之取得系統支持的字體
{
var strFonts="";
for(var i=1;i<dlgHelper.fonts.count;i++)
{
strFonts=strFonts+dlgHelper.fonts(i)+"|";
}
alert(strFonts);
}
function getBlockFormat()//Dilog Helper對象的使用之取得系統中塊的格式信息(如:標題1、標題2....)
{
var strBlockFormat="";
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
strBlockFormat=strBlockFormat+dlgHelper.BlockFormats(i)+"|";
}
alert(strBlockFormat);
}

function createTxtLink()//給選中的文本創建鏈接
{
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)並根據選擇不同的BlockFormat改變樣式
//函數fillselect()和changeformat()
//對execCommand的一點說明:Executes a command over the given selection or text range
function fillselect()
{
var item=document.createElement("OPTION")
item.text="請選擇";
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);
}
//取得驅動器類型,調用如: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);//取得卷標
}

</script>
-------------------------
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章