客户端获取电脑硬件信息

前台JS

function GetLocalIPAddress()
{//IP
     var obj = null;
     var rslt = "";
     try
     {
         obj = new ActiveXObject("rcbdyctl.Setting");
         rslt = obj.GetIPAddress;
         obj = null;
     }
     catch(e)
     {
         //异常发生
     }
   
     return rslt;
}

var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var ip= GetLocalIPAddress();
var service = locator.ConnectServer(ip);


function cpuInfo() {//CPU 信息 
 var properties = service.ExecQuery("SELECT * FROM Win32_Processor");
 var e = new Enumerator (properties);

 for (;!e.atEnd();e.moveNext ())
 {
        var p = e.item ();
        document.getElementById ("lblCPU").value=p.Name;
    }
};
function mainBoard() {//主板信息
var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard");
var e = new Enumerator (properties);
var info="

";
  info+="";
  for (;!e.atEnd();e.moveNext ())
    {
       var p = e.item (); 
       document.getElementById("lblManufacturer").value= p.Manufacturer.replace(/[ ]/g,"");
    }
};
function diskinfo() {//硬盘
var properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive");
var e = new Enumerator (properties);
for (;!e.atEnd();e.moveNext ()) {
  var p = e.item (); 
  document.getElementById ('<%=lblDisk.ClientID%>').value= Math.round(p.size/1000/1000/1000)+"G"

}
};
function vgainfo() {//显卡
var properties = service.ExecQuery("SELECT * FROM Win32_VideoController");
var e = new Enumerator (properties);
for (;!e.atEnd();e.moveNext ()) {
  var p = e.item (); 
  document.getElementById ("lblVGA").value= p.Caption
}
};
function dvdinfo() {//光驱
var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive");
var e = new Enumerator (properties);
for (;!e.atEnd();e.moveNext ()) {
  var p = e.item (); 
 document.getElementById ("lblDVDROM").value= p.Caption
}
};
function raminfo() {//内存
var properties = service.ExecQuery("SELECT * FROM Win32_LogicalMemoryConfiguration");
var e = new Enumerator (properties);
for (;!e.atEnd();e.moveNext ()) {
  var p = e.item (); 
  document.getElementById ("lblRAM").value= Math.round(p.TotalPhysicalMemory/1024/1024)+"G"
}

/*
fnShowPrcName("Win32_StartupCommand") // 系统自动启动程序
*/

function pcInfo() { //所有信息
    cpuInfo();
    mainBoard();
    diskinfo();
    vgainfo();
    dvdinfo();
    raminfo();
}

或者后台写:

Imports System
Imports System.Management
Imports System.Management.Instrumentation
Imports Microsoft.Win32
Imports System.Runtime.InteropServices

其中Management 需要引用的

 '''


    '''
    '''

    '''
    '''
    Private Function GetCpuID() As String
        Try
            Dim mc As Management.ManagementClass
            Dim moc As Management.ManagementObjectCollection
            Dim mo As Management.ManagementObject
            mc = New Management.ManagementClass("Win32_processor")
            moc = mc.GetInstances()
            For Each mo In moc
                cpuInfo = mo.Properties("DeviceID").Value.ToString()
            Next mo
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return "unknow"
    End Function
    '''
    '''
    '''

    '''
    '''
    Private Function GetTotalPhysicalMemory() As String
        Try
            Dim mc As Management.ManagementClass
            Dim moc As Management.ManagementObjectCollection
            Dim mo As Management.ManagementObject
            mc = New Management.ManagementClass("Win32_LogicalMemoryConfiguration")
            moc = mc.GetInstances()
            For Each mo In moc
                cpuInfo = mo.Properties("TotalPhysicalMemory").Value.ToString() / 1024 / 1024
                'physicMenCap = Math.ceil(System.TotalPhysicalMemory / 1024 / 1024)
            Next mo
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return "unknow"
    End Function
    '''
    ''' 获取硬盘大小
    '''

    '''
    '''
    Private Function GetDisk() As String
        Try
            Dim mc As Management.ManagementClass
            Dim moc As Management.ManagementObjectCollection
            Dim mo As Management.ManagementObject
            mc = New Management.ManagementClass("Win32_DiskDrive")
            moc = mc.GetInstances()
            For Each mo In moc
                cpuInfo = CType(mo.Properties("size").Value.ToString() / (1000 * 1000 * 1000), Integer) & "G"
                'physicMenCap = Math.ceil(System.TotalPhysicalMemory / 1024 / 1024)
            Next mo
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return "unknow"
    End Function
    Private Function GetVGA() As String
        Try
            Dim mc As Management.ManagementClass
            Dim moc As Management.ManagementObjectCollection
            Dim mo As Management.ManagementObject
            mc = New Management.ManagementClass("Win32_VideoController")
            moc = mc.GetInstances()
            For Each mo In moc
                cpuInfo = mo.Properties("Caption").Value.ToString()
                'physicMenCap = Math.ceil(System.TotalPhysicalMemory / 1024 / 1024)
            Next mo
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return "unknow"
    End Function
    Private Function GetCDROM() As String
        Try
            Dim mc As Management.ManagementClass
            Dim moc As Management.ManagementObjectCollection
            Dim mo As Management.ManagementObject
            mc = New Management.ManagementClass("Win32_CDROMDrive")
            moc = mc.GetInstances()
            For Each mo In moc
                cpuInfo = mo.Properties("Caption").Value.ToString()
                physicMenCap = Math.ceil(System.TotalPhysicalMemory / 1024 / 1024)
            Next mo
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return "unknow"
    End Function

    Private Function GetMain() As String
        Try
            Dim mc As Management.ManagementClass
            Dim moc As Management.ManagementObjectCollection
            Dim mo As Management.ManagementObject
            mc = New Management.ManagementClass("Win32_BaseBoard")
            moc = mc.GetInstances()
            For Each mo In moc
                cpuInfo = mo.Properties("SerialNumber").Value.ToString()
                physicMenCap = Math.ceil(System.TotalPhysicalMemory / 1024 / 1024)
            Next mo
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return "unknow"
    End Function

 

 

你可能感兴趣的:(asp.net)

主板信息