JS怎么獲取客戶端計(jì)算機(jī)硬件信息
JS怎么獲取客戶端計(jì)算機(jī)硬件信息
在IE 中運(yùn)行的js 是受到諸多限制的, 尤其是關(guān)于activex , 輕易是不能運(yùn)行的, 而獲取計(jì)算機(jī)名等就是這種需要activex 才能得到的信息之一,那么JS語(yǔ)言是如何獲取客戶端計(jì)算機(jī)硬件信息的呢?今天就讓學(xué)習(xí)啦小編來(lái)教下大家吧,快來(lái)看看吧,希望能讓大家有所收獲!
JS獲取客戶端計(jì)算機(jī)硬件信息代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
var info = allinfo();
document.write(info);
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
info = pcInfo();
document.write(info);
//獲取瀏覽器相關(guān)信息
function allinfo(){
var userLanguage = navigator.userLanguage; // 用戶在自己的操作系統(tǒng)上設(shè)置的語(yǔ)言(火狐沒(méi)有)
var userAgent = navigator.userAgent; //包含以下屬性中所有或一部分的字符串:appCodeName,appName,appVersion,language,platform
var systemLanguage = navigator.systemLanguage; // 用戶操作系統(tǒng)支持的默認(rèn)語(yǔ)言(火狐沒(méi)有)
info+="瀏覽器屬性信息: "+userAgent+"<br />";
info+="用戶設(shè)置的操作系統(tǒng)語(yǔ)言: "+userLanguage+"<br />";
info+="操作系統(tǒng)支持的默認(rèn)語(yǔ)言: "+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序列號(hào):" + p.ProcessorID + "</td></tr>";
info+="<tr><td >"+p.Caption+"</td></tr>";
info+="<tr><td >CPU編號(hào):"+p.DeviceID+"</td></tr>";
info+="<tr><td >CPU型號(hào):" + p.Name + "</td></tr>";
info+="<tr><td >CPU狀態(tài):" + p.CpuStatus + "</td></tr>";
info+="<tr><td >CPU可用性:" + p.Availability + "</td></tr>";
info+="<tr><td >CUP Level:" + p.Level + "</td></tr>";
info+="<tr><td >主機(jī)名稱:" + 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 >是否開(kāi)啟:" + p.PoweredOn + "</td></tr>";
info+="<tr><td >型號(hào):" + 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);
//內(nèi)存信息
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'>內(nèi)存信息 </td></tr>";
info+="<tr style='color: red'><td >內(nèi)存總量:";
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 >可用物理內(nèi)存:" +physicMenCap + "M</td></tr>";
info+="</table>";
return info;
}
//獲取網(wǎng)絡(luò)連接信息
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'>網(wǎng)絡(luò)連接信息:</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;
}
// 獲取操作系統(tǒng)信息
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;
}
//獲取用戶帳號(hào)信息
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'>用戶帳號(hào)信息:</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;
}
//獲取系統(tǒng)組帳號(hào)信息
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'>系統(tǒng)組帳號(hào)信息:</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;
}
//獲取系統(tǒng)管理組信息
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'>系統(tǒng)管理組信息:</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;
}
//獲取系統(tǒng)安裝的服務(wù)信息
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'>系統(tǒng)安裝的服務(wù)信息:</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") // 系統(tǒng)自動(dòng)啟動(dòng)程序
*/
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>