js擷取用戶端電腦硬體資訊與系統資訊

來源:互聯網
上載者:User
<html><head><script>var info = allinfo();document.write(info);var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer(".");info = pcInfo();document.write(info);//擷取瀏覽器相關資訊function allinfo(){var userLanguage = navigator.userLanguage;     // 使用者在自己的作業系統上設定的語言(Firefox沒有)var userAgent = navigator.userAgent;   //包含以下屬性中所有或一部分的字串:appCodeName,appName,appVersion,language,platformvar systemLanguage = navigator.systemLanguage;    // 使用者作業系統支援的預設語言(Firefox沒有)info+="瀏覽器屬性資訊: "+userAgent+"<br />";info+="使用者佈建的作業系統語言: "+userLanguage+"<br />";info+="作業系統支援的預設語言: "+systemLanguage+"<br />";return info;}/******************************************以上為瀏覽器資訊,以下為pc資訊************************************************/function cpuInfo() {//CPU 資訊  var properties = service.ExecQuery("SELECT * FROM Win32_Processor"); var e = new Enumerator (properties); var info = "<table border=1>";info+="<tr  bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450' >CPU 資訊</td></tr>";for (;!e.atEnd();e.moveNext ()) {   var p = e.item ();   info+="<tr style='color: red'><td >CPU序號:" + p.ProcessorID + "</td></tr>";  info+="<tr><td >"+p.Caption+"</td></tr>";  info+="<tr><td >CPU編號:"+p.DeviceID+"</td></tr>";  info+="<tr><td >CPU型號:" + p.Name + "</td></tr>";  info+="<tr><td >CPU狀態:" + p.CpuStatus + "</td></tr>";  info+="<tr><td >CPU可用性:" + p.Availability + "</td></tr>";  info+="<tr><td >CUP Level:" + p.Level + "</td></tr>";  info+="<tr><td >主機名稱:" + p.SystemName + "</td></tr>";  info+="<tr><td >Processor Type:" + p.ProcessorType + "</td></tr>";} info+="</table>";return info;}function mainBoard() {//主板資訊 var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard"); var e = new Enumerator (properties); var info="<table border=1>";   info+="<tr bgcolor='#CDEDED' style='font-weight: bold;'><td width='450'>主板資訊 </td></tr>";for (;!e.atEnd();e.moveNext ()) {   var p = e.item ();    info+="<tr style='color: red'><td >主板ID:" + p.SerialNumber + "</td></tr>";  info+="<tr><td >" + p.HostingBoard + "</td></tr>";  info+="<tr><td >製造商:" + p.Manufacturer + "</td></tr>";  info+="<tr><td >是否開啟:" + p.PoweredOn + "</td></tr>";  info+="<tr><td >型號:" + p.Product + "</td></tr>";  info+="<tr><td >版本:" + p.Version + "</td></tr>";} info+="</table>"; return info;} //擷取Ram資訊function raminfo(){var system=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item();     var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024);//記憶體資訊     var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory"));     for (var mem=[],i=0;!memory.atEnd();memory.moveNext()){   mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed};}var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>記憶體資訊 </td></tr>";  info+="<tr style='color: red'><td >記憶體總量:";  memDX = 0;  for(var mi=0;mi<mem.length;mi++){memDX += mem[mi].cap;  }  info+= memDX + "M</td></tr>";  info+="<tr style='color: red'><td >可用實體記憶體:" +physicMenCap + "M</td></tr>";info+="</table>"; return info;}//擷取網路連接資訊function ipinfo(){var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE");var e = new Enumerator (properties);var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>網路連接資訊:</td></tr>";var i=1;for (;!e.atEnd();e.moveNext ()){var p = e.item ();info+="<tr style='color: red'><td >MAC地址"+i+":" + p.MACAddress + "</td></tr>";info+="<tr style='color: red'><td >IP地址"+i+":" + p.IPAddress(0) + "</td></tr>";i++;}info+="</table>"; return info;}// 擷取作業系統資訊function osinfo(){var properties = service.ExecQuery("SELECT * FROM Win32_OperatingSystem");var e = new Enumerator (properties);var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>OS資訊:</td></tr>";var i=1;for (;!e.atEnd();e.moveNext ()){var p = e.item ();info+="<tr style='color: red'><td > " + p.BootDevice + "</td></tr>";info+="<tr style='color: red'><td>" + p.BuildNumber + "</td></tr>";info+="<tr style='color: red'><td>" + p.BuildType + "</td></tr>";info+="<tr style='color: red'><td>" + p.Caption + "</td></tr>";info+="<tr style='color: red'><td>" + p.CodeSet + "</td></tr>";info+="<tr style='color: red'><td>" + p.CountryCode + "</td></tr>";info+="<tr style='color: red'><td>" + p.CreationClassName + "</td></tr>";info+="<tr style='color: red'><td>" + p.CSCreationClassName + "</td></tr>";info+="<tr style='color: red'><td>" + p.CSDVersion + "</td></tr>";info+="<tr style='color: red'><td>" + p.CSName + "</td></tr>";info+="<tr style='color: red'><td>" + p.CurrentTimeZone + "</td></tr>";info+="<tr style='color: red'><td>" + p.DataExecutionPrevention_Available + "</td></tr>";info+="<tr style='color: red'><td>" + p.DataExecutionPrevention_32BitApplications + "</td></tr>";info+="<tr style='color: red'><td>" + p.DataExecutionPrevention_Drivers + "</td></tr>";info+="<tr style='color: red'><td>" + p.DataExecutionPrevention_SupportPolicy + "</td></tr>";info+="<tr style='color: red'><td>" + p.Debug + "</td></tr>";info+="<tr style='color: red'><td>" + p.Description + "</td></tr>";info+="<tr style='color: red'><td>" + p.Distributed + "</td></tr>";info+="<tr style='color: red'><td>" + p.EncryptionLevel + "</td></tr>";info+="<tr style='color: red'><td>" + p.ForegroundApplicationBoost + "</td></tr>";info+="<tr style='color: red'><td>" + p.FreePhysicalMemory + "</td></tr>";info+="<tr style='color: red'><td>" + p.FreeSpaceInPagingFiles + "</td></tr>";info+="<tr style='color: red'><td>" + p.FreeVirtualMemory + "</td></tr>";info+="<tr style='color: red'><td>" + p.InstallDate + "</td></tr>";info+="<tr style='color: red'><td>" + p.LargeSystemCache + "</td></tr>";info+="<tr style='color: red'><td>" + p.LastBootUpTime + "</td></tr>";info+="<tr style='color: red'><td>" + p.LocalDateTime + "</td></tr>";info+="<tr style='color: red'><td>" + p.Locale + "</td></tr>";info+="<tr style='color: red'><td>" + p.Manufacturer + "</td></tr>";info+="<tr style='color: red'><td>" + p.MaxNumberOfProcesses + "</td></tr>";info+="<tr style='color: red'><td>" + p.MaxProcessMemorySize + "</td></tr>";info+="<tr style='color: red'><td>" + p.Name + "</td></tr>";info+="<tr style='color: red'><td>" + p.NumberOfLicensedUsers + "</td></tr>";info+="<tr style='color: red'><td>" + p.NumberOfProcesses + "</td></tr>";info+="<tr style='color: red'><td>" + p.NumberOfUsers + "</td></tr>";info+="<tr style='color: red'><td>" + p.OperatingSystemSKU + "</td></tr>";info+="<tr style='color: red'><td>" + p.Organization + "</td></tr>";info+="<tr style='color: red'><td>" + p.OSArchitecture + "</td></tr>";info+="<tr style='color: red'><td>" + p.OSLanguage + "</td></tr>";info+="<tr style='color: red'><td>" + p.OSProductSuite + "</td></tr>";info+="<tr style='color: red'><td>" + p.OSType + "</td></tr>";info+="<tr style='color: red'><td>" + p.OtherTypeDescription + "</td></tr>";info+="<tr style='color: red'><td>" + p.PAEEnabled + "</td></tr>";info+="<tr style='color: red'><td>" + p.PlusProductID + "</td></tr>";info+="<tr style='color: red'><td>" + p.PlusVersionNumber + "</td></tr>";info+="<tr style='color: red'><td>" + p.PortableOperatingSystem + "</td></tr>";info+="<tr style='color: red'><td>" + p.Primary + "</td></tr>";info+="<tr style='color: red'><td>" + p.ProductType + "</td></tr>";info+="<tr style='color: red'><td>" + p.RegisteredUser + "</td></tr>";info+="<tr style='color: red'><td>" + p.SerialNumber + "</td></tr>";info+="<tr style='color: red'><td>" + p.ServicePackMajorVersion + "</td></tr>";info+="<tr style='color: red'><td>" + p.ServicePackMinorVersion + "</td></tr>";info+="<tr style='color: red'><td>" + p.SizeStoredInPagingFiles + "</td></tr>";info+="<tr style='color: red'><td>" + p.Status + "</td></tr>";info+="<tr style='color: red'><td>" + p.SuiteMask + "</td></tr>";info+="<tr style='color: red'><td>" + p.SystemDevice + "</td></tr>";info+="<tr style='color: red'><td>" + p.SystemDirectory + "</td></tr>";info+="<tr style='color: red'><td>" + p.SystemDrive + "</td></tr>";info+="<tr style='color: red'><td>" + p.TotalSwapSpaceSize + "</td></tr>";info+="<tr style='color: red'><td>" + p.TotalVirtualMemorySize + "</td></tr>";info+="<tr style='color: red'><td>" + p.TotalVisibleMemorySize + "</td></tr>";info+="<tr style='color: red'><td>" + p.Version + "</td></tr>";//info+="<tr style='color: red'><td>" + p.MUILanguages[] + "</td></tr>";i++;}info+="</table>"; return info;}//擷取使用者帳號資訊function uidinfo(){var properties = service.ExecQuery("SELECT * FROM Win32_UserAccount");var e = new Enumerator (properties);var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>使用者帳號資訊:</td></tr>";var i=1;for (;!e.atEnd();e.moveNext ()){var p = e.item ();info+="<tr style='color: red'><td > " + i + ":" + p.AccountType + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Caption + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Description + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Disabled + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Domain + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.FullName + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.InstallDate + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.LocalAccount + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Lockout + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Name + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.PasswordChangeable + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.PasswordExpires + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.PasswordRequired + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.SID + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.SIDType + "</td></tr>";info+="<tr style='color: red'><td > " + i + ":" + p.Status + "</td></tr>";i++;}info+="</table>"; return info;}//擷取系統組帳號資訊function sysuidinfo(){var properties = service.ExecQuery("SELECT * FROM Win32_GroupUser");var e = new Enumerator (properties);var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td colspan='3'>系統組帳號資訊:</td></tr>";info+="<tr style='color: red'><td >id</td><td >GroupComponent</td><td >PartComponent</td></tr>";var i=1;for (;!e.atEnd();e.moveNext ()){var p = e.item ();info+="<tr style='color: red'><td > " + i + "</td>";info+="<td>" + p.GroupComponent + "</td>";info+="<td>" + p.PartComponent + "</td></tr>";i++;}info+="</table>"; return info;}//擷取系統管理組資訊function sysmadinfo(){var properties = service.ExecQuery("SELECT * FROM Win32_Group");var e = new Enumerator (properties);var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td colspan='10'>系統管理組資訊:</td></tr>";info+="<tr style='color: red'><td >id</td><td >Caption</td><td >Description</td><td >Domain</td><td >InstallDate</td><td >LocalAccount</td><td >Name</td><td >SID</td><td >SIDType</td><td >Status</td></tr>";var i=1;for (;!e.atEnd();e.moveNext ()){var p = e.item ();info+="<tr style='color: red'><td>" + i + "</td>";info+="<td>" + p.Caption + "</td>";info+="<td>" + p.Description + "</td>";info+="<td>" + p.Domain + "</td>";info+="<td>" + p.InstallDate + "</td>";info+="<td>" + p.LocalAccount + "</td>";info+="<td>" + p.Name + "</td>";info+="<td>" + p.SID + "</td>";info+="<td>" + p.SIDType + "</td>";info+="<td>" + p.Status + "</td></tr>";i++;}info+="</table>"; return info;}//擷取系統安裝的服務資訊function sysserinfo(){var properties = service.ExecQuery("SELECT * FROM Win32_Service");var e = new Enumerator (properties);var info="<table border=1>"; info+="<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td colspan='26'>系統安裝的服務資訊:</td></tr>";info+="<tr style='color: red'><td>id</td><td>AcceptPause</td><td>AcceptStop</td><td>Caption</td><td>CheckPoint</td><td>CreationClassName</td><td>Description</td><td>DesktopInteract</td><td>DisplayName</td><td>ErrorControl</td><td>ExitCode</td><td>InstallDate</td><td>Name</td><td>PathName</td><td>ProcessId</td><td>ServiceSpecificExitCode</td><td>ServiceType</td><td>Started</td><td>StartMode</td><td>StartName</td><td>State</td><td>Status</td><td>SystemCreationClassName</td><td>SystemName</td><td>TagId</td><td>WaitHint</td></tr>";var i=1;for (;!e.atEnd();e.moveNext ()){var p = e.item ();info+="<tr style='color: red'><td> " + i + "</td> ";info+=" <td>" + p.AcceptPause + "</td> ";info+=" <td>" + p.AcceptStop + "</td> ";info+=" <td>" + p.Caption + "</td> ";info+=" <td>" + p.CheckPoint + "</td> ";info+=" <td>" + p.CreationClassName + "</td> ";info+=" <td>" + p.Description + "</td> ";info+=" <td>" + p.DesktopInteract + "</td> ";info+=" <td>" + p.DisplayName + "</td> ";info+=" <td>" + p.ErrorControl + "</td> ";info+=" <td>" + p.ExitCode + "</td> ";info+=" <td>" + p.InstallDate + "</td> ";info+=" <td>" + p.Name + "</td> ";info+=" <td>" + p.PathName + "</td> ";info+=" <td>" + p.ProcessId + "</td> ";info+=" <td>" + p.ServiceSpecificExitCode + "</td> ";info+=" <td>" + p.ServiceType + "</td> ";info+=" <td>" + p.Started + "</td> ";info+=" <td>" + p.StartMode + "</td> ";info+=" <td>" + p.StartName + "</td> ";info+=" <td>" + p.State + "</td> ";info+=" <td>" + p.Status + "</td> ";info+=" <td>" + p.SystemCreationClassName + "</td> ";info+=" <td>" + p.SystemName + "</td> ";info+=" <td>" + p.TagId + "</td> ";info+=" <td>" + p.WaitHint + "</td></tr>";i++;}info+="</table>"; return info;}/*fnShowPrcName("Win32_StartupCommand")// 系統自動啟動程式*/function pcInfo() {//所有資訊var info=cpuInfo();info+=mainBoard();info+=ipinfo();info+=osinfo();info+=uidinfo();info+=sysuidinfo();info+=sysmadinfo();info+=sysserinfo();return info;} </script></head><body><div id="elInfo" ></div></body></html>

使用時把以上代碼儲存為html檔案

通過WMI來實現擷取用戶端電腦硬體及系統資訊:1//系統資訊擷取 
2function getSysInfo(){ 
3 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 
4 var service = locator.ConnectServer("."); 
5 //CPU資訊 
6 var cpu = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item(); 
7 var cpuType=cpu.Name,hostName=cpu.SystemName; 
8 //記憶體資訊 
9 var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory")); 
10 for (var mem=[],i=0; !memory.atEnd(); memory.moveNext()) mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed} 
11 //系統資訊 
12 var system=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item(); 
13 var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024),curUser=system.UserName,cpuCount=system.NumberOfProcessors
14 
15 return {cpuType:cpuType,cpuCount:cpuCount,hostName:hostName,curUser:curUser,memCap:physicMenCap,mem:mem}
16}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.