您的位置:首页 >> 编程开发 >> .NET >> 其它 >> 正文
其它 RSS
 

.NET中得到计算机硬件信息的一些功能

http://www.rdxx.com 05年07月27日 21:45 CSDN 我要投稿

关键词: 硬件 , 计算机 , 功能 , 信息 , .NET , 计算

在.NET中得到计算机硬件信息的一些功能

得到显示器分辨率
Dim X As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Dim Y As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
MsgBox("您的显示器分辨率是:" & X & " X " & Y)

得到特殊文件夹的路径
'"Desktop"桌面文件夹路径
MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
'"Favorites"收藏夹路径
MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.Favorites))
'"Application Data"路径
MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))

'通用写法
'Dim SPEC As String = Environment.GetFolderPath(Environment.SpecialFolder.XXXXXXX)
'XXXXXXX是特殊文件夹的名字

得到操作系统版本信息
MsgBox(Environment.OSVersion.ToString)

得到当前登录的用户名
MsgBox(Environment.UserName)

得到当前应用程序的路径
MsgBox(Environment.CurrentDirectory)

打开和关闭CD-ROM
'先新建模块
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 Integer
End Module

'打开CD-ROM
Dim lRet As Long
lRet = mciSendString("set cdAudio door open", 0&, 0, 0)

'关闭CD-ROM
Dim lRet As Long
lRet = mciSendString("set cdAudio door Closed", 0&, 0, 0)

得到计算机IP和计算机全名
Dim MYIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
MsgBox("您的IP地址:" & (MYIP.AddressList.GetValue(0).ToString))
MsgBox("您的计算机全名:" & (MYIP.HostName.ToString))

使用win32_operatingSystem (wmi Class)得到计算机信息
'添加ListBox在Form1_Load事件里,并引用system.Managment
Dim opSearch As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Dim opInfo As ManagementObject
For 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("Computer name: " & opInfo("csname").ToString())
  ListBox1.Items.Add("Windows Directory: " & opInfo("windowsdirectory").ToString())
Next

列出计算机安装的全部字体,并添加到ListBox
'新建Form并添加ListBox和Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fntCollection As InstalledFontCollection = New InstalledFontCollection()
Dim fntFamily() As FontFamily
fntFamily = fntCollection.Families
ListBox1.Items.Clear()
Dim i As Integer = 0
For i = 0 To fntFamily.Length - 1
  ListBox1.Items.Add(fntFamily(i).Name)
Next
End Sub

使用Win32_Processor列出处理器的信息
Imports System.Management
Public Class Form1
  Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

  Public Sub New()
    MyBase.New()

    '该调用是 Windows 窗体设计器所必需的。
    InitializeComponent()

上一页 下一页


 
 
标签: 硬件 , 计算机 , 功能 , 信息 , .NET , 计算 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站