在.net中得到计算机硬件信息的一些功能
hr4|AwA/ AF57Chi H|[W!X~ @`jfPbQW 2qK6r] >9'f%tQ/ 得到显示器分辨率
;?13\AP Dim X As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Am0fh@ ~ Dim Y As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
|Ry?wFZ 2 MsgBox("您的显示器分辨率是:" & X & " X " & Y)
V|Pq!Wmb? ]7G%O!Fl] 得到特殊文件夹的路径
Jmbdi|(@U '"Desktop"桌面文件夹路径
Q6EXw_q MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
qXbBwsJ '"Favorites"收藏夹路径
[(s_ MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.Favorites))
R[,dH;y '"Application Data"路径
h4TGL6l MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
ZbO5bRC ( 0'Y?ET6h '通用写法
&rO9#y@ 'Dim SPEC As String = Environment.GetFolderPath(Environment.SpecialFolder.XXXXXXX)
[ !hn 'XXXXXXX是特殊文件夹的名字
<cOWu, UO(qN 得到操作系统版本信息
Ea6"j]m' MsgBox(Environment.OSVersion.ToString)
BlR-v?}y sWZA3^ 得到当前登录的用户名
35iw0Jxd! MsgBox(Environment.UserName)
C ROnia| S>! r^ 1 得到当前应用程序的路径
^zI$ro^9 MsgBox(Environment.CurrentDirectory)
H%<`QZ%ET La_@&0 打开和关闭CD-ROM
B]^qi ZP '先新建模块
?]$:!Qvk Module mciAPIModule
F|e6hH== Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
Z-4Dd=4O (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
"" 7, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
['j~s@:j; End Module
+0Ku B@64D '打开CD-ROM
2QQ=DD ?@ Dim lRet As Long
^9Y9 HQ lRet = mciSendString("set cdAudio door open", 0&, 0, 0)
8@.y @D.@5 Z;R&e5:t '关闭CD-ROM
ya)CR# Dim lRet As Long
AH2q1OcZ lRet = mciSendString("set cdAudio door Closed", 0&, 0, 0)
vtzl6@P /+_1) 0Z\?5(wY 得到计算机IP和计算机全名
0B'r_UR Dim MYIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
C6wSacli/ MsgBox("您的IP地址:" & (MYIP.AddressList.GetValue(0).ToString))
i C`m~k3T MsgBox("您的计算机全名:" & (MYIP.HostName.ToString))
)%M@K)@$7 2@/k" 使用win32_operatingSystem (wmi Class)得到计算机信息
Amzj Z"B '添加ListBox在Form1_Load事件里,并引用system.Managment
OYw.;*7 Dim opSearch As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Wa#W&09Z} Dim opInfo As ManagementObject
umUj,/L For Each opInfo In opSearch.Get()
nrS6[x:T1 ListBox1.Items.Add("Name: " & opInfo("name").ToString())
WJZC_I{ ListBox1.Items.Add("Version: " & opInfo("version").ToString())
4 )a< p ListBox1.Items.Add("Manufacturer: " & opInfo("manufacturer").ToString())
O3 [z( ListBox1.Items.Add("Computer name: " & opInfo("csname").ToString())
&@iPN"C? ListBox1.Items.Add("Windows Directory: " & opInfo("windowsdirectory").ToString())
LQ\)#7]v5 Next
Yr"xe2pbkp #)SbM_4K 列出计算机安装的全部字体,并添加到ListBox
7 9@c|=Z '新建Form并添加ListBox和Button
I~D0Trmq Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
&*1,q5$tJ+ Dim fntCollection As InstalledFontCollection = New InstalledFontCollection()
Y "Oakd Dim fntFamily() As FontFamily
@Tm67]i fntFamily = fntCollection.Families
6%tF@`DIU ListBox1.Items.Clear()
0ci/RZL]u Dim i As Integer = 0
Vu~^>~Nd For i = 0 To fntFamily.Length - 1
2C@ ?N ListBox1.Items.Add(fntFamily(i).Name)
4UWD"!)Z9u Next
MN&@G| End Sub
lfqzUhI& s l-?2O- 使用Win32_Processor列出处理器的信息
rj_FjQ Imports System.Management
i(cJ Public Class Form1
42*i bbe Inherits System.Windows.Forms.Form
g~.W,5; RFsPKX #region " Windows 窗体设计器生成的代码 "
Ee= :gV9 ziH$M Public Sub New()
fo;>!z|nA MyBase.New()
[tQ<!&4 wq/J,. '该调用是 Windows 窗体设计器所必需的。
rP[cQNhL InitializeComponent()
act%BW)y~ ,C#Y&`xn '在 InitializeComponent() 调用之后添加任何初始化
zS$VU_i-; { ,a Ufc End Sub
0-J=BC6P s!5fr=@ '窗体重写 dispose 以清理组件列表。
*H! r(F_]" Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
|]|\ be6 If disposing Then
+Ao{r?#U If Not (components Is Nothing) Then
}UKp*O (L components.Dispose()
"']K~$+9jJ End If
@ hW-[f End If
-V hb MyBase.Dispose(disposing)
0^~q>6TX End Sub
Z*+2r#C v|e;Z= 'Windows 窗体设计器所必需的
sw; VQ]Ft Private components As System.ComponentModel.IContainer
9)>%dcQ.o/ XR8~Y| t '注意: 以下过程是 Windows 窗体设计器所必需的
!u.q;> '可以使用 Windows 窗体设计器修改此过程。
A; }0)#0 '不要使用代码编辑器修改它。
7sQYB/: Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
nA7>(<A[ Friend WithEvents Button1 As System.Windows.Forms.Button
3{T0Q3Z <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
U:(xmC;@ Me.ListBox1 = New System.Windows.Forms.ListBox
[GwNZC9 Me.Button1 = New System.Windows.Forms.Button
o9<,7hy Me.SuspendLayout()
|>f5-|gB '
s8 UWE?! 'ListBox1
q[ 7 v& '
EpB#B3U Me.ListBox1.Location = New System.Drawing.Point(8, 8)
$0]$& Me.ListBox1.Name = "ListBox1"
l-c Av8f` Me.ListBox1.Size = New System.Drawing.Size(280, 186)
s{`,gfa Me.ListBox1.TabIndex = 0
pu'Gsv;5| '
IJKK;oXha} 'Button1
L#b`yv '
3:n+/M=d Me.Button1.Location = New System.Drawing.Point(56, 208)
EeFk+_8*[ Me.Button1.Name = "Button1"
e-Nxx]n6 Me.Button1.Size = New System.Drawing.Size(168, 32)
-FI '{-`c Me.Button1.TabIndex = 1
KV_ aDV Me.Button1.Text = "装载计算机处理器信息"
C"7g3j!n '
va8V4Y| 'Form1
guVt("xb '
o,ZVCl{{rw Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
T/-%VpU;# Me.ClientSize = New System.Drawing.Size(296, 254)
VXWT+{;, & Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.ListBox1})
Oax8m&IhO Me.Text = "计算机处理器信息"
kGTcU[2m., Me.ResumeLayout(False)
`F>I8OgS C7D{N<a6 End Sub
s:<+~8Q P(/> #end Region
4/"#x|n7 jjJ;{o 5N Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
G7-[x\|6( Handles Button1.Click
C{k!yWn0 x|1PaMUv Dim ProcQuery As New SelectQuery("Win32_Processor")
%{S'GB q Dim ProcSearch As New ManagementObjectSearcher(ProcQuery)
g +G/JT~ Dim ProcInfo As ManagementObject
yZn=p T o U, nZX For Each ProcInfo In ProcSearch.Get()
g& XcPg Call processorfamily(ProcInfo("Family").ToString)
L(gmI"it9 ListBox1.Items.Add("Description: " & ProcInfo("Description").ToString())
7AAoAE ListBox1.Items.Add("caption: " & ProcInfo("caption").ToString())
zuRI1s+E: ListBox1.Items.Add("Architecture: " & ProcInfo("Architecture").ToString())
^c7d<,|T Call processortype(ProcInfo("ProcessorType").ToString())
fLV^Aq Call CpuStat(ProcInfo("CpuStatus").ToString)
\(T%bj ListBox1.Items.Add("MaxClockSpeed: " & ProcInfo("MaxClockSpeed").ToString() & "MHZ")
L.i+rzG ListBox1.Items.Add("L2CacheSpeed: " & ProcInfo("L2CacheSpeed").ToString() & "MHZ")
}{(b`;'Q9 ListBox1.Items.Add("ExtClock: " & ProcInfo("L2CacheSpeed").ToString() & "MHZ")
]hTNDn'x< ListBox1.Items.Add("ProcessorId: " & ProcInfo("ProcessorId").ToString())
.vei}Ps ListBox1.Items.Add("AddressWidth: " & ProcInfo("AddressWidth").ToString() & "Bits")
#zra1c;h ListBox1.Items.Add("DataWidth: " & ProcInfo("DataWidth").ToString() & "Bits")
>j025*hs ListBox1.Items.Add("Version: " & ProcInfo("Version").ToString())
=|`WO= ListBox1.Items.Add("ExtClock: " & ProcInfo("ExtClock").ToString() & "MHZ")
R,lfHU i Next
{~UZ/:Hm End Sub
G?NRuaoa Function processorfamily(ByVal procssfam)
mEe[ _Mz Dim processtype
m f`Uo6L Select Case procssfam
0)(x jT9y Case 1
t}"ja\ processtype = "Other"
|c<4Pyi<k Case 2
]wpN"w" processtype = "Unknown "
\We_m sQ Case 3
xjQ'1Rma processtype = "8086 "
pdu|>#[9 Case 4
t 9fgE z] processtype = "80286 "
jc!=&f-h Case 5
L.^%O6Rl processtype = "80386 "
t[[ >7J++: Case 6
r"o!F_T processtype = "80486 "
G@go5'^O Case 7
'GMr processtype = "8087 "
QJYK\nt-dC Case 8
"4 @8VvV processtype = "80287 "
Xn?{t*{ Case 9
pQg8:`b processtype = "80387 "
)\9ZD M! Case 10
IXoR}R Y6 processtype = "80487 "
=P$YIb="U Case 11
WrlFcwuK processtype = "Pentium brand "
;wA;\X;0B Case 12
)oK/Onhh processtype = "Pentium Pro "
Ra\g OOOr Case 13
e?25(e processtype = "Pentium II "
?^ H'kp Case 14
&a)dZk processtype = "Pentium processor with MMX technology "
E,4"U>y Case 15
Q/z]U3 processtype = "Celeron "
%~h0J" Case 16
^(c<D? processtype = "Pentium II Xeon "
k^*eXP3=@ Case 17
x?L7o^T~q processtype = "Pentium III "
yUJ)wNT>xw Case 18
87v9^LR[a+ processtype = "M1 Family "
1 N`6t Case 19
eoiS processtype = "M2 Family "
Q*`tL@@tR Case 24
8 q7<|SF( processtype = "K5 Family "
p HGRL Case 25
I)H">%BC processtype = "K6 Family "
-6d!1js78 Case 26
P&oosy') processtype = "K6-2 "
8fN.A#( +e Case 27
5!||"`g+ processtype = "K6-3 "
r'$`TuA Case 28
j|Mm ;>@ processtype = "AMD Athlon Processor Family "
0v9(4w s X Case 29
V.C7O5F processtype = "AMD Duron Processor "
C~HW$U^-qT Case 30
jf})f8S/G processtype = "AMD2900 Family "
A7Y-`.&[i Case 31
n!7,F520 processtype = "K6-2+ "
s#S8K;xzp Case 32
gBl7)h37 processtype = "Power PC Family "
n?HMI (} Case 33
yX]" Gu ! processtype = "Power PC 601 "
CL=*Fll- Case 34
/I|)Lg0.< processtype = "Power PC 603 "
2k>(^E "S Case 35
rP(dM_c processtype = "Power PC 603+ "
Isl"B Case 36
ov-Wa8uu/ processtype = "Power PC 604 "
j85r=U Case 37
-oSRn processtype = "Power PC 620 "
\0V{N}kcL Case 38
}hOW R processtype = "Power PC X704 "
jW0c6wB2 Case 39
E5y_bO> ^ processtype = "Power PC 750 "
ou-a}"{R% Case 48
=DIvs+%Kv processtype = "Alpha Family "
`9vPD?>MC Case 49
J//$b)91g processtype = "Alpha 21064 "
9^x@/ Case 50
Fv,@*z@ke processtype = "Alpha 21066 "
,e fko2B Case 51
V4&<GQ'NL processtype = "Alpha 21164 "
']$,2{$:m Case 52
K d^AFMH processtype = "Alpha 21164PC "
CC&s<=\ Case 53
E5j.2%!# processtype = "Alpha 21164a "
9J;ZZ/3 Case 54
$Ou'\Xx processtype = "Alpha 21264 "
"=^il{ Case 55
AwJ[C(8v processtype = "Alpha 21364 "
_ Hd |\.@ Case 64
ly r)Hcg processtype = "MIPS Family "
{5kd Es` Case 65
U=`+yUh processtype = "MIPS R4000 "
2@6^_k E 0 Case 66
Yo+o* ^22D processtype = "MIPS R4200 "
QCKv4tg< Case 67
ZdP@UkP processtype = "MIPS R4400 "
b/K$+0wak Case 68
[TZofKiGH processtype = "MIPS R4600 "
XcM,{JG Case 69
uB6]r|:Qf processtype = "MIPS R10000 "
DKj%)/toB Case 80
=4TRHz# processtype = "SPARC Family "
@?AZsl%X Case 81
A= V)5v8U processtype = "SuperSPARC "
w)Wby~1 =Y Case 82
>l^a<idh processtype = "microSPARC II "
ng{kfc6bT6 Case 83
=Ys8KJ^.m processtype = "microSPARC IIep "
v/|Lx1: Case 84
Q{U\0OV processtype = "UltraSPARC "
:2y@Nx1 Case 85
6AT"dX Z processtype = "UltraSPARC II "
H.Rc!!St} Case 86
k^"J- S_` processtype = "UltraSPARC IIi "
(i7T`< | Case 87
&/V_`^ processtype = "UltraSPARC III "
%)S"v ` Case 88
OT;%/} processtype = "UltraSPARC IIIi "
. jnR=2@ Case 96
iKz{3S processtype = "68040 "
$OdfjB[ Case 97
P0_{u;47 processtype = "68xxx Family "
`~s%T}3u' Case 98
NB4lAm+Y processtype = "68000 "
Mqfn @K X Case 99
yBUq\Y: _~ processtype = "68010 "
c:6v*l?6\ Case 100
% 3 *sg> processtype = "68020 "
([;*N Case 101
(aS;+{)] processtype = "68030 "
X`> yY?1c Case 112
u4NN]r?n%H processtype = "Hobbit Family "
S9Q$ _q Case 120
7N}cHx2P processtype = "Crusoe TM5000 Family "
`RNjI6X` Case 121
Hd=/zJ&q processtype = "Crusoe TM3000 Family "
Gfw%f<; Case 128
< [CX(~Y processtype = "Weitek "
=('&NH Case 130
gT&tv5=2zA processtype = "Itanium Processor "
_>>FuJ- Case 144
z$Ud+0! processtype = "PA-RISC Family "
H4)T0` Case 145
5uy &b2 o% processtype = "PA-RISC 8500 "
D)7I| Case 146
wu\WEPL"" processtype = "PA-RISC 8000 "
N 22 q*( Case 147
(Sfmm6 N6 processtype = "PA-RISC 7300LC "
P5<t3- Case 148
jqnzthF>T processtype = "PA-RISC 7200 "
gQ uj?x Case 149
3I/4 rNz processtype = "PA-RISC 7100LC "
jHFuMAH8L Case 150
}_}yXwuW processtype = "PA-RISC 7100 "
P\dncqF{]U Case 160
`D`>F}2V< processtype = "V30 Family "
#eaVn +t Case 176
j+TZfrli# processtype = "Pentium III Xeon "
)@TeVGhB Case 177
e& processtype = "Pentium III Processor with Intel SpeedStep Technology "
CXC~CF Case 178
tg+WMHu. processtype = "Pentium 4 "
uG5V~.OhO Case 179
|~:;|G] processtype = "Intel Xeon "
fBEX"9],B Case 180
zG]Zqpor> processtype = "AS400 Family "
XJDbR Case 181
.x:NTMJjg processtype = "Intel Xeon processor MP "
%4-&}^vS Case 182
Q2v;h 8 processtype = "AMD AthlonXP Family "
9tAR6 Case 183
tSw$1'|# processtype = "AMD AthlonMP Family "
*:[ ]Mx Case 184
+ @\KL< processtype = "Intel Itanium 2 "
9(d0,t-.? Case 185
1'EE%L processtype = "AMD Opteron Family "
SXD=AjwAc_ Case 190
j/-f :ZV processtype = "K7 "
!R(1bt7Au Case 200
SZ:!rMQ processtype = "IBM390 Family "
fT4nh&tk- Case 201
p(_7, { processtype = "G4 "
vqLvWM " Case 202
MiH5",b processtype = "G5 "
fpKF(@H Case 250
!) NARl processtype = "i860 "
55gF?_1A Case 251
|=Okvl6} processtype = "i960 "
)lD9iKTB Case 260
j^ YC0B processtype = "SH-3 "
f{~S Rnx) Case 261
.J)Pa processtype = "SH-4 "
5Wl#-_ Case 280
)z)a processtype = "ARM "
9;"8:gB4[ Case 281
E6bz={ processtype = "StrongARM "
KHhR+QO}H Case 300
?MB|Xd^8} processtype = "6x86 "
n+w'4H( Case 301
Dxo!= processtype = "MediaGX "
L{1z& 7n Case 302
VNbO.7[ processtype = "MII "
{>T v> Case 320
N3-]{ processtype = "WinChip "
AL3%sKq Case 350
q(uE,7v processtype = "DSP "
N;TzDs Case 500
R\#D0Ci|a processtype = "Video Processor "
l I}aHJL End Select
, C{]K ListBox1.Items.Add("Family: " & processtype)
Y;jjWlOnX dh@cP End Function
`zAdh.4/ Function CpuStat(ByVal CpuStNUM)
=gEs%>Cy Dim stat
Z@LW_8kZm Select Case CpuStNUM
2J>V>0tT Case 0
v@6!|wQ( stat = "Unknown "
^LSMF`O4 Case 1
@ "s1 stat = "CPU Enabled "
/Ppka4g g Case 2
@/`N]]Zs stat = "CPU Disabled by User via BIOS Setup "
0}X" } 30 Case 3
^ghb Kj: stat = "CPU Disabled By BIOS (POST Error) "
JDafJj7 Case 4
{rRM7(3V stat = "CPU is Idle "
+O,jX4xpD[ Case 5
2hI`?m:uA stat = "Reserved "
R^a*RC r Case 6
{ nH }>B stat = "Reserved "
!W+iv374 Case 7
kAu],=g stat = "Other "
@,C C4 End Select
QdCTO ListBox1.Items.Add("CpuStatus: " & stat)
rG?oT5?m End Function
0K*xC Function processortype(ByVal proctypenum)
-k|Rw[s (r Dim proctype
E[(kiBey@> Select Case proctypenum
R^24$<7z Case 1
TdNoX0xdWh proctype = "Other "
7te']a Case 2
=iv4n<z proctype = "Unknown "
Da(G Aph Case 3
Hi0Y! G proctype = "Central Processor "
G,>(<]9( Case 4
D2@i ` proctype = "Math Processor "
g.F~1nm` Case 5
?8a+br proctype = "DSP Processor "
XzR8't Case 6
'D+"tMekf proctype = "Video Processor "
T%u]Pn<l End Select
"9x)5] ListBox1.Items.Add("Processor Type: " & proctype)
}ox Ln B;7|'H_ End Function
w`1 hZ%, End Class
da-'<0iQ
查看本文来源