JavaScript Dapatkan Informasi Perangkat Keras Komputer dan Sistem Klien
Melalui WMI untuk mendapatkan perangkat keras komputer dan informasi sistem klien:
Salin kode kode sebagai berikut:
fungsi getsysinfo () {
var local = ActivexObject baru ("wbemscripting.swbemlocator");
var service = local.connectserver (".");
// Informasi CPU
var cpu = enumerator baru (service.execQuery ("Select * from win32_processor"). item () ;;);
var cputype = cpu.name, hostName = cpu.systemname;
// informasi memori
var memori = enumerator baru (service.execQuery ("Select * from win32_physicalmemory");););
Untuk (var mem = [], i = 0;! Memory.atend (); memori.movenext ()) mem [i ++] = {cap: memory.item () .itemm () .speed}
// informasi sistem
var system = enumerator baru (service.execQuery ("SELECT * DARI WIN32_COMPUTERSYSTEM"). Item ();
Var physicmencap = math.ceil (System.totalPhysicalMemory/1024/1024), curuser = System.username, cpucount = System.numberProcessorsors
Return {cputype: cputype, cpucount: cpucount, hostname: hostname, curuser: curuser, memcap: physicmencap, mem: mem}
}
Implementasi kode terutama mencakup bagian -bagian ini:
Lewati First the ActiveXObject baru ("WBEMSCRIPTING.SWBEMLOCATOR");
Melalui local.connectserver (".");
Anda juga dapat mengakses komputer lain).
Melalui service.execquery ("Pilih * dari Win32_Processor"), pernyataan SQL yang serupa (pada kenyataannya, informasi sistem juga disimpan dalam file seperti database dalam perhitungan) untuk mendapatkan set catatan yang kita butuhkan.
Buat objek yang disebutkan melalui enumertor baru, dan Anda dapat melintasi informasi di bawah ini.
Catatan: Premis menjalankan adalah untuk memodifikasi pengaturan keselamatan browser, "memungkinkan ActiveX, yang tidak ditandai sebagai aman,"
Pengoperasian skrip ".
Berikut adalah informasi utama pengguna CPU, memori, dan sistem.
Untuk informasi lebih lanjut. Kelas informasi umum tercantum di bawah ini:
Win32_processor // prosesor CPU
Win32_physicalmemory // memori fisik
Win32_keyboard // keyboard
Win32_pointingdevice // point input device, seperti mouse
Win32_diskdrive // driver hard drive
Win32_cdromdrive // drive CD
Win32_baseboard // motherboard
Win32_bios // chip bios
Win32_parallelport //
Win32_serialport // port serial
Win32_sounddevice // Pengaturan Multimedia
Win32_USBController // USB Controller
Win32_networkadapter // adaptor jaringan
Win32_networkadapterconfiguration // Pengaturan Adaptor Jaringan
Win32_printer // printer
Win32_printerconfiguration // pengaturan printer
Win32_printjob // tugas printer
Win32_tcpipprintorport // port printer
Win32_potsmodem // modem
Win32_potsmodemtoserialport // port modem
Win32_desktopmonitor // display
Win32_videocontroller // detail kartu grafis.
Win32_videosettings // Mode tampilan yang didukung oleh kartu grafis.
Win32_timezone // zona waktu
Win32_systemdriver // driver
Win32_diskpartition // Partisi disk
Win32_logicaldisk // Disk logika
Win32_LogicalMemoryConfiguration // Konfigurasi Memori Logis
Win32_Pagefile // Informasi File Halaman Sistem
Win32_pageFilesetting // Pengaturan file halaman
Win32_bootconfiguration // konfigurasi startup sistem
Win32_operatingsystem // Informasi Sistem Operasi
Win32_StartupCommand // Program Startup Otomatis Sistem
Win32_Service // Layanan Instalasi Sistem
Win32_group // Grup Manajemen Sistem
Win32_Groupuser // Nomor Akun Grup Sistem
Win32_useraccount // akun pengguna
Win32_process // proses sistem
Win32_thread // utas sistem
Win32_share // Bagikan
Win32_networkclient // klien online yang diinstal
WIN32_NETWORKPROTOCOL // Protokol Jaringan Terpasang
Untuk informasi lengkap dan daftar rinci kelas WMI Win32, silakan merujuk ke MSDN:
http://msdn2.microsoft.com/en-s/library/aa394084 (vs.85) .aspx
Contoh:
Salin kode kode sebagai berikut:
Function button1_onClick () {// Informasi CPU
var local = ActivexObject baru ("wbemscripting.swbemlocator");
var service = local.connectserver (".");
Var properties = service.execQuery ("SELECT * DARI WIN32_PROCESOR");
var e = enumerator baru (properti);
document.write ("<tabel border = 1>");
untuk (;! e.atend (); e.movenext ())
{{
var p = e.Item ();
document.write ("<ter>");
document.write ("<td>" + p.caption + "</td>");
document.write (<td> " + p.deviceid +" </td> ");
document.write ("<td>" " + p.name +" </td> ");
document.write ("<td>" " + p.cpustatus +" </td> ");
document.write ("<td>" " + p.availability +" </td> ");
document.write ("<td>" " + p.level +" </td> ");
document.write ("<td>" " + p.processorid +" </td> ");
document.write ("<td>" " + p.systemname +" </td> ");
document.write ("<td>" + p.processortype + "</td>");
document.write ("</tr>);
}
document.write ("</abless>");
}
Function button2_onClick () {// Informasi CD-ROM
var local = ActivexObject baru ("wbemscripting.swbemlocator");
var service = local.connectserver (".");
Var properties = service.execquery ("SELECT * DARI WIN32_CDROMDRIVE");
var e = enumerator baru (properti);
document.write ("<tabel border = 1>");
untuk (;! e.atend (); e.movenext ())
{{
var p = e.Item ();
document.write ("<ter>");
document.write ("<td>" + p.caption + "</td>");
document.write ("<td>" " + p.descript +" </td> ");
document.write ("<td>" + p.drive + "</td>");
document.write ("<td>" " + p.status +" </td> ");
document.write ("<td>" " + p.medialoaded +" </td> ");
document.write ("</tr>);
}
document.write ("</abless>");
}
Function button3_onClick () {// Informasi keyboard
var local = ActivexObject baru ("wbemscripting.swbemlocator");
var service = local.connectserver (".");
Var properties = service.execQuery ("Pilih * dari Win32_Keyboard");
var e = enumerator baru (properti);
document.write ("<tabel border = 1>");
untuk (;! e.atend (); e.movenext ())
{{
var p = e.Item ();
document.write ("<ter>");
document.write ("<td>" " + p.descript +" </td> ");
document.write ("<td>" " + p.name +" </td> ");
document.write ("<td>" " + p.status +" </td> ");
document.write ("</tr>);
}
document.write ("</abless>");
}
Button Function4_onClick () {// Informasi Motherboard
var local = ActivexObject baru ("wbemscripting.swbemlocator");
var service = local.connectserver (".");
Var properties = service.execquery ("SELECT * DARI WIN32_BASEBOARD");
var e = enumerator baru (properti);
document.write ("<tabel border = 1>");
untuk (;! e.atend (); e.movenext ())
{{
var p = e.Item ();
document.write ("<ter>");
document.write ("<td>" " + p.hostboard +" </td> ");
document.write ("<td>" " + p.manufacturer +" </td> ");
document.write ("<td>" + p.poweredon + "</td>");
document.write ("<td>" + p.product + "</td>");
Document.write ("<td>" " + P. P. P. P. P." </td> ");
document.write ("<td>" " + p.version +" </td> ");
document.write ("</tr>);
}
document.write ("</abless>");
}
Selain itu, Anda juga dapat memperoleh informasi yang relevan melalui cara -cara berikut:
Salin kode kode sebagai berikut:
<Html> <Head> <title> WMI Scripting html </iteme>
<Meta http-equiv = konten-tipe konten = "text/html; charset = gb2312">
<Bahasa skrip = jScript event = "onCompleted (hResult, perrorObject, pasynccontext)" untuk = foo>
Document.Forms [0] .txtmacadr.value = unescape (macAddr);
Document.Forms [0] .txtipaddr.Value = unescape (ipaddr);
document.forms [0] .txtdnsname.value = unescape (sdnsname);
//document.formbar.submit ();
</script>
<bahasa skrip = jscript event = onobjectready (objObject, objasynccontext) untuk = foo>
if (objObject.ipeNabled! = null && objObject.ipeNabled! = "tidak terdefinisi" && objObject.ipeNabled == true)
{{
If (objObject.macaddress! = Null && objObject.macaddress! = "Tidak terdefinisi")
MacAddr = Object.MacAddress;
if (objObject.ipEnabled && objObject.ipaddress (0)! = null && objObject.ipadddress (0)! = "tidak terdefinisi")
Ipaddr = object.ipaddress (0);
if (objObject.dnshostname! = null && objObject.dnshostname! = "tidak terdefinisi")
sdnsname = object.dnshostname;
}
</script>
<Meta content = "mshtml 6.00.2800.1106" name = Generator> </head>
<body>
<Objek id = classId lokal = clsid: 76a64158-cb41-11d1-8b02-00600806d9b6 viewastext> </ject>
<Objek id = foo classId = clsid: 75718c9a-f029-11d1-a1aC-004fb6c223> </bodes>
<bahasa skrip = jscript>
var service = local.connectserver ();
var macaddr;
var ipaddr;
var domainddr;
var sdnsname;
Service.security_.impersonationlevel = 3;
Service.instancesofasync (foo, 'win32_networkAdapterConfiguration');
</script>
<Form id = "formfoo" name = "formbar" action = "index.do" method = "Post"> <input value = "00-11-11-b4-52-l" name = "txtmacaddr"> <input Value = "210.42.38.50" name = "txtipaddr"> <input value = "zhupan" name = "txtdnsname"> </body> </html>
Salin kode kode sebagai berikut:
Faktanya, yang paling penting adalah menggunakan dua ActiveX:
<Objek id = classId lokal = clsid: 76a64158-cb41-11d1-8b02-00600806d9b6 viewastext> </ject>
<Objek id = foo classId = clsid: 75718c9a-f029-11d1-a1aC-004fb6c223> </bodes>
Namun, kedua ActiveX ini dibangun secara sistematis, tanpa harus mengunduh atau mendaftar.
Pekerjaan berikutnya adalah berinteraksi dengan ActiveX dengan skrip
<Html>
<head>
<bahasa skrip = "javascript" type = "text/javascript">
fungsi getCode () {
var local = ActivexObject baru ("wbemscripting.swbemlocator");
var service = local.connectserver (".");
Var properties = service.execQuery ("SELECT * DARI WIN32_NETWORKADAPTERConfiguration di mana ipenabld = true");
var e = enumerator baru (properti);
document.write ("<tabel border = 1>");
untuk (;! e.atend (); e.movenext ()) {
var p = e.Item ();
//If.ip.ipadddress (0)! = Null && p.ipaddress (0)! ) .0.1 ") {{
document.write ("<ter>");
document.write ("<td>" " + p.servicename +" </td> ");
document.write ("<td>" " + p.macaddress +" </td> ");
document.write ("<td>" " + p.ipaddress (0) +" </td> ");
document.write ("</tr>);
// Merusak;
//}
}
document.write ("</abless>");
}
</script>
</head>
<body>
<tombol id = "test" value = "test" onclick = "getCode ()"> test </button>
</body>
</html>
Kelas Win32_NetWorkAdapterConfiguration: CIM_SETTING
{{
boolean arpalwayssourceroute;
Boolean Arpuseethersnap;
Keterangan string;
String DatabasePath;
Boolean deadgwdetectenabled;
string defaultipgateway [];
Uint8 defaultTos;
Uint8 defaulttl;
deskripsi string;
Boolean dhcpenabled;
Datetime dhcpleaseexpires;
Datetime dhcpleaseobtaine;
string dhcpserver;
string dnsdomain;
string dnsdomainuffixsearchordr [];
Boolean dnsenabled forwinsrsolution;
string dnshostname;
String DnsServerSearchOrder [];
Boolean domaindnsregistratinabled;
Uint32 ForwardBuffermemory;
Boolean fulldnsregistrationnabled;
uint16 gatewaycostmetric [];
Uint8 igmPlevel;
Indeks UInt32;
InterfaceIndex uint32;
string ipaddress [];
Uint32 ipconnectionmetric;
Boolean ipenabled;
Boolean ipfiltersecurityAnpled;
Boolean ipportsecurityedableed;
string ipsecpermitipprotocols [];
string ipsecpermittcpports [];
string ipsecpermitudports [];
string ipsubnet [];
Boolean ipusezerobroadcast;
string ipxaddress;
Boolean ipxenabled;
Uint32 ipxframetype [];
Uint32 ipxmediatype;
String IPXNetWorkNumber [];
String ipxvirtualNetNumber;
UINT32 KeepaliveInterval;
Uint32 Keepalivetime;
string macaddress;
Uint32 mtu;
Uint32 numforwardpackets;
Boolean pMtubhDetectenabled;
Boolean pmtudiscoveryed;
layanan string;
string aturedId;
Uint32 tcpipnetbiosoptions;
UInt32 TCPMAXConnectretransmisisions;
UINT32 TCPMAXDATARETRANSMISSI;
Uint32 tcpnumConnections;
Boolean tcpuserfc11122gentpointer;
Uint16 tcpwindowsize;
Boolean Winsenablelmhostslookup;
String winshostlookupfile;
String WinsprimaryServer;
String winsscopeId;
String WinssecondaryServer;
};