Some functions of getting computer hardware information in .NET

xiaoxiao2021-03-05  56

Some functions of getting computer hardware information in .NET

Get display resolution DIM X as short = system.windows.Forms.Screen.PrimaryScreen.bounds.widthdim y as short = system.windows.Forms.Screen.primaryScreen.bounds.Heightmsgbox ("Your display resolution is:" & X & "x" & y)

Get path to special folders' "Desktop" Desktop folder path MsgBox (Environment.GetFolderPath (Environment.SpecialFolder.DesktopDirectory)) ' "Favorites" Favorites path MsgBox (Environment.GetFolderPath (Environment.SpecialFolder.Favorites))' "Application Data "path msgbox (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData))

'Universal Writing' DIM Spec AS String = Environment.GetFolderPath (Environment.SpecialFolder.xxxxxxx) 'XXXXXXX is the name of a special folder

Get the operating system version information msgbox (Environment.OSVERSION.TOSTRING)

Get the current login username msgbox (environments.username)

Get the path of the current application MSGBox (Environment.currentDirectory)

Opening and closing the CD-ROM 'first new module Module mciAPIModule Declare Function mciSendString Lib "winmm.dll" Alias ​​"mciSendStringA" _ (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _ ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As IntegerEnd Module

'Open CD-ROM DIM LRET AS Longlret = McIndstring ("Set Cdaudio Door Open", 0 &, 0, 0)

'Turn off CD-ROM DIM LRET AS Longlret = McISendstring ("Set Cdaudio Door Closed", 0 &, 0, 0)

Get computer IP and computer full name Dim myip as system.net.iphostentry = system.net.dns.getHostByName (System.Net.dns.getHostName) MSGBOX ("Your IP Address:" & (Myip.addressList.GetValue (0 ) .Tostring)) MSGBOX ("Your computer full name:" & (myip.hostname.tostring))

Use win32_operatingSystem (wmi Class) computer information obtained 'in Form1_Load added ListBox incident, and reference system.ManagmentDim opSearch As New ManagementObjectSearcher ( "SELECT * FROM Win32_OperatingSystem") Dim opInfo As ManagementObjectFor Each opInfo In opSearch.Get () ListBox1.Items. Add ("Name:" & opinfo ("name"). TOSTRING ()) Listbox1.items.add ("Version:" & opinfo ("Version"). Tostring ()) Listbox1.Items.Add ("Manufacturer:" & opinfo ("manufacturer"). Tostring ()) ListBox1.items.Add ("CSName:" & opinfo ("csname"). Tostring ()) Listbox1.Items.Add ("Windows Directory:" & opinfo (" windowsdirectory "). ToString ()) Next List all fonts installed on the computer, and added to the ListBox 'and add a new Form ListBox and ButtonPrivate Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim fntCollection As InstalledFontCollection = New InstalledFontCollection () Dim fntFamily () As FontFamilyfntFamily = fntCollection.FamiliesListBox1.Items.Clear () Dim i As Integer = 0For i = 0 To fntFamily.Length - 1 ListBox1.Items.Add (fntFamily (i). Name) NEXTEN D SUB

Use Win32_Processor to list the processor information Imports System.ManagementPublic Class Form1 inherits System.Windows.Forms.form

#Region "Windows Form Designer Generated Code"

Public Sub new () mybase.new ()

'This call is required for the Windows Form Designer. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Form rewriting Dispose to clean up the list of components. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End Sub

'WINDOWS Form Designer The private components as system.componentmodel.icontainer' Note: The following process is required for the Windows Form Designer 'You can use the Windows Form Designer to modify this process. 'Don't modify it using the code editor. Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Friend WithEvents Button1 As System.Windows.Forms.Button Private Sub InitializeComponent () Me.ListBox1 = New System.Windows.Forms.ListBox Me. Button1 = new system.windows.Forms.Button Me.SuspendLayout () '' listbox1 'me.listbox1.location = new system.drawing.point (8, 8) me.listbox1.name = "listbox1" me.listbox1.size = New System.drawing.Size (280, 186) Me.ListBox1.tabindex = 0 '' Button1 'me.button1.location = new system.drawing.point (56, 208) me.button1.name = "Button1" ME .Button1.size = new system.drawing.size (168, 32) me.button1.tabindex = 1 me.button1.text = "Load computer processor information" '' Form1 'me.autoscalebasesize = new system.drawing.size (5, 13) me.clientsize = new system.drawing.size (296, 254) me.controls.addrange (new system.windows.Forms.Control () {me.button1, me.listbox1}) me.text = "Computer processor information" me.resumelayout False)

End Sub

#End region

Private sub button1_click (byval sender as system.Object, byval e as system.eventargs) _ handles button1.click

Dim Procquery As New SelectQuery ("Win32_Processor") Dim Procsearch As New ManagementObjectSearcher (Procquery) Dim Procinfo As ManagementObjectObjectObject

For Each Procinfo in procsearch.get () Call ProcessorFamily ("Family"). Tostring) ListBox1.Items.Add ("Description:" & Procinfo ("Description"). Tostring ()) ListBox1.Items.add (" Caption: "& procinfo (" caption "). Tostring ()) ListBox1.Items.Add (" Architecture: ". Tostring ()) Call Processortype (Procinfo (" Processortype "). Tostring () Call Cpustat (Procinfo ("cpustatus"). TOSTRING) ListBox1.Items.Add ("MaxClockSpeed:"). Tostring () & "MHz") listbox1.items.add ("L2Cachespeed:" & Procinfo ("L2Cachespeed"). Tostring () & "MHz") listbox1.items.add ("extclock:" & procinfo ("l2cachespeed"). Tostring () & "mhz") listbox1.items.add ("Processorid: "& Procinfo (" processorid "). Tostring ()) ListBox1.Items.Add (" AddressWidth: "). Tostring () &" bits ") listbox1.items.add (" DataWidth: " Procinfo ("DataWidth"). Tostring () & "bits") listbox1.items.add ("Version:" & procinfo ("Version ") .ToString ()) ListBox1.Items.Add (" ExtClock: ".) ToString () &" "& ProcInfo (" ExtClock MHZ ") Next End Sub Function processorfamily (ByVal procssfam) Dim processtype Select Case procssfam Case 1 processtype = "Other" case 2 processtype = "unknown" case 3 processtype = "8086" Case 4 ProcesSstype = "80286"

Case 5 processtype = "80386" Case 6 processtype = "80486" Case 7 processtype = "8087" Case 8 processtype = "80287" Case 9 processtype = "80387" Case 10 processtype = "80487" Case 11 processtype = "Pentium brand" Case 12 processtype = "Pentium Pro" Case 13 processtype = "Pentium II" Case 14 processtype = "Pentium processor with MMX technology" Case 15 processtype = "Celeron" Case 16 processtype = "Pentium II Xeon" Case 17 processtype = "Pentium III "Case 18 processtype =" M1 Family "Case 19 processtype =" M2 Family "Case 24 processtype =" K5 Family "Case 25 processtype =" K6 Family "Case 26 processtype =" K6-2 "Case 27 processtype =" K6-3 "Case 28 Processtype =" AMD Athlon Processor Family "Case 29 Processtype =" AMD DURON P rocessor "Case 30 processtype =" AMD2900 Family "Case 31 processtype =" K6-2 "Case 32 processtype =" Power PC Family "Case 33 processtype =" Power PC 601 "Case 34 processtype =" Power PC 603 "Case 35 processtype = "Power PC 603 " Case 36 Processtype = "Power PC 604" Case 37 Processtype =

"Power PC 620" Case 38 processtype = "Power PC X704" Case 39 processtype = "Power PC 750" Case 48 processtype = "Alpha Family" Case 49 processtype = "Alpha 21064" Case 50 processtype = "Alpha 21066" Case 51 processtype = "Alpha 21164" Case 52 processtype = "Alpha 21164PC" Case 53 processtype = "Alpha 21164a" Case 54 processtype = "Alpha 21264" Case 55 processtype = "Alpha 21364" Case 64 processtype = "MIPS Family" Case 65 processtype = " MIPS R4000 "Case 66 processtype =" MIPS R4200 "Case 67 processtype =" MIPS R4400 "Case 68 processtype =" MIPS R4600 "Case 69 processtype =" MIPS R10000 "Case 80 processtype =" SPARC Family "Case 81 processtype =" SuperSPARC " Case 82 processtype = "MicrosParc II" case 83 processtype = "Microsparc II ep "Case 84 processtype =" UltraSPARC "Case 85 processtype =" UltraSPARC II "Case 86 processtype =" UltraSPARC IIi "Case 87 processtype =" UltraSPARC III "Case 88 processtype =" UltraSPARC IIIi "Case 96 processtype =" 68040 "Case 97 Processtype = "68xxx family" Case 98 Processtype = "68000"

Case 99 processtype = "68010" Case 100 processtype = "68020" Case 101 processtype = "68030" Case 112 processtype = "Hobbit Family" Case 120 processtype = "Crusoe TM5000 Family" Case 121 processtype = "Crusoe TM3000 Family" Case 128 processtype = "Weitek" Case 130 processtype = "Itanium Processor" Case 144 processtype = "PA-RISC Family" Case 145 processtype = "PA-RISC 8500" Case 146 processtype = "PA-RISC 8000" Case 147 processtype = "PA-RISC 7300LC "Case 148 processtype =" PA-RISC 7200 "Case 149 processtype =" PA-RISC 7100LC "Case 150 processtype =" PA-RISC 7100 "Case 160 processtype =" V30 Family "Case 176 processtype =" Pentium III Xeon "Case 177 Processtype = "Pentium III Processor with Intel Speedstep Technology" Case 178 Processtype = "Pentium 4 "Case 179 processtype =" Intel Xeon "Case 180 processtype =" AS400 Family "Case 181 processtype =" Intel Xeon processor MP "Case 182 processtype =" AMD AthlonXP Family "Case 183 processtype =" AMD AthlonMP Family "Case 184 processtype = "Intel Itanium 2" Case 185 Processtype = "AMD Opteron Family" Case 190 Processtype =

"K7" Case 200 processtype = "IBM390 Family" Case 201 processtype = "G4" Case 202 processtype = "G5" Case 250 processtype = "i860" Case 251 processtype = "i960" Case 260 processtype = "SH-3" Case 261 processtype = "SH-4" Case 280 processtype = "ARM" Case 281 processtype = "StrongARM" Case 300 processtype = "6x86" Case 301 processtype = "MediaGX" Case 302 processtype = "MII" Case 320 processtype = "WinChip" Case 350 processtype = "DSP" case 500 processtype = "Video processor" end select listbox1.items.add ("Family:" & processtype)

End Function Function CpuStat (ByVal CpuStNUM) Dim stat Select Case CpuStNUM Case 0 stat = "Unknown" Case 1 stat = "CPU Enabled" Case 2 stat = "CPU Disabled by User via BIOS Setup" Case 3 stat = "CPU Disabled By BIOS (Post error) "case 4 stat =" cpu is id "case 5 stat =" reserved "case 6 stat =" reserved "case 7 stat =" ot "end select listbox1.items.add (" cpustatus: "& stat) End Function Function processortype (ByVal proctypenum) Dim proctype Select Case proctypenum Case 1 proctype = "Other" Case 2 proctype = "Unknown" Case 3 proctype = "Central Processor" Case 4 proctype = "Math Processor" Case 5 proctype = "DSP Processor "Case 6 Proctype =" Video Processor "End Select ListBox1.Items.Add (" Processor Type: "& Procty) End Functionend Class

转载请注明原文地址:https://www.9cbs.com/read-31962.html

New Post(0)