用JavaScript得到機器名,登入網域及登入使用者名稱

來源:互聯網
上載者:User

<script language="JavaScript">
var WshNetwork = new ActiveXObject("WScript.Network");
alert("Domain = " + WshNetwork.UserDomain);
alert("Computer Name = " + WshNetwork.ComputerName);
alert("User Name = " + WshNetwork.UserName);
</script>

會彈出來一個安全層級的對話方塊。

常用JS指令碼

<script  language="jscript">
//取得網路上的印表機
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>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.