真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

vb.net獲取磁盤信息 vbnet讀取文件內(nèi)容

VB.NET 中使用 combobox 控件獲取磁盤信息

先引用 System.ManageMent

10年的嶧城網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整嶧城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“嶧城網(wǎng)站設(shè)計(jì)”,“嶧城網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim HDDDeviceQuery As New Management.SelectQuery("Win32_DiskDrive")

Dim HDDDeviceSearch As New Management.ManagementObjectSearcher(HDDDeviceQuery)

Dim HDDDeviceInfo As Management.ManagementObject

For Each HDDDeviceInfo In HDDDeviceSearch.Get()

ComboBox1.Items.Add("HDD Description: " HDDDeviceInfo("caption").ToString())

ComboBox1.Items.Add("HDD BytesPerSector: " HDDDeviceInfo("BytesPerSector").ToString())

'ComboBox1.Items.Add("HDD CompressionMethod: " HDDDeviceInfo("CompressionMethod").ToString())

ComboBox1.Items.Add("HDD Index: " HDDDeviceInfo("Index").ToString())

'ComboBox1.Items.Add("HDD InstallDate: " HDDDeviceInfo("InstallDate").ToString())

ComboBox1.Items.Add("HDD Manufacturer: " HDDDeviceInfo("Manufacturer").ToString())

ComboBox1.Items.Add("HDD Partitions: " HDDDeviceInfo("Partitions").ToString() Space(1) GetLastDev())

ComboBox1.Items.Add("HDD Size: " Int(Val(HDDDeviceInfo("Size").ToString()) / 2 ^ 30) " GBytes")

ComboBox1.Items.Add("HDD TotalCylinders: " HDDDeviceInfo("TotalCylinders").ToString())

ComboBox1.Items.Add("HDD TotalSectors: " HDDDeviceInfo("TotalSectors").ToString())

ComboBox1.Items.Add("HDD TracksPerCylinder: " HDDDeviceInfo("TracksPerCylinder").ToString())

ComboBox1.Items.Add("HDD TotalHeads: " HDDDeviceInfo("TotalHeads").ToString())

ComboBox1.Items.Add("HDD TotalTracks: " HDDDeviceInfo("TotalTracks").ToString())

ComboBox1.Items.Add("HDD SectorsPerTrack: " HDDDeviceInfo("SectorsPerTrack").ToString())

ComboBox1.Items.Add("HDD SCSILogicalUnit: " HDDDeviceInfo("SCSILogicalUnit").ToString())

Next

End Sub

Public Function GetLastDev() As String

GetLastDev = ""

Dim r As Short = My.Computer.FileSystem.Drives.Count

For i As Short = 0 To r - 1 Step 1

GetLastDev = GetLastDev My.Computer.FileSystem.Drives(i).Name ":"

Next

Return GetLastDev

End Function

End Class

VB6中如何獲取磁盤信息?

樓上的朋友可能有點(diǎn)小小的誤會(huì)樓主的意思了,

樓主朋友可能要現(xiàn)在已經(jīng)分好區(qū)的空間大小,已用空間、剩余空間。

當(dāng)然我也不敢保證誰對誰錯(cuò),

我還是把我的理解 然后 也把代碼貼出來讓樓主看看吧

下面代碼的功能:顯示光驅(qū)當(dāng)前分區(qū),以及各個(gè)盤的總空間,剩余空間。

當(dāng)然。如果要硬盤總空間,我們可以把所有空間加起來,就達(dá)到要求了。

希望下面的代碼對樓主有用!

'硬盤空間大小 以及光驅(qū)

'添加Drive1 Label1 Label2

Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Const DRIVE_CDROM = 5

Public drivenm As String, cddrive As String

Private Sub Form_Load()

'查找CD-ROM的驅(qū)動(dòng)器號

cddrive = ""

For i = 65 To 90

If GetDriveType(Chr$(i) ":\") = DRIVE_CDROM Then

cddrive = UCase(Chr$(i)) ":\"

Exit For

End If

Next i

drivenm = "c:"

Label1.AutoSize = True

Label2.AutoSize = True

Drive1.Left = (Me.Width - Drive1.Width) \ 2

Drive1.Drive = "c"

Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2

gethd

End Sub

Private Sub Form_Activate()

MsgBox "你的光驅(qū)在:" cddrive

End Sub

Private Sub Drive1_Change()

drivenm = Mid(Drive1.Drive, 1, 3)

gethd

End Sub

Private Sub gethd() '得知硬盤容量

On Error Resume Next

Dim dfs, cl1, cl2, sec1, byt1, tspace, getdiskvolm, lSize, kk%

Dim hdtype$, hdspace$, hdfspace$

dfs = GetDiskFreeSpace(drivenm, sec1, byt1, cl1, cl2)

If dfs Then

cl2 = Int(cl2 * sec1 / 1024 * byt1)

lSize = Len(Format$(cl2, "#########"))

If lSize 11 Then

kk = 11 - lSize

End If

hdspace = Space(kk) + Format$(cl2, "#########") + " KBytes"

cl1 = Int(cl1 * sec1 / 1024 * byt1)

lSize = Len(Format$(cl1, "#########"))

If lSize 11 Then

kk = 11 - lSize

End If

hdfspace = Space(kk) + Format$(cl1, "#########") + " KBytes"

Else

hdspace = ""

hdfspace = ""

End If

Label1.Caption = "你的" drivenm "盤的總空間是:" Format(Str(Val(hdspace) / 1024 / 1024), "##0.0") + " G"

Label2.Caption = "你的" drivenm "盤剩余空間是:" Format(Str(Val(hdfspace) / 1024), "###,##0.0") + " M"

If UCase(Left(Drive1.Drive, 2)) = UCase(Left(cddrive, 2)) Then

If Val(Label1.Caption) = 0 And Val(Label2.Caption) = 0 Then

MsgBox "這張盤是空的光盤"

Else

If Val(Label1.Caption) 0 And Val(Label2.Caption) 0 Then

MsgBox "這張盤不是空的光盤,但還有空間"

Else

If Val(Label1.Caption) 0 And Val(Label2.Caption) = 0 Then

MsgBox "這張盤是寫滿并終止的光盤"

End If

End If

End If

End If

End Sub

vb.net 磁盤文件列表,界面如圖,在.net下如何實(shí)現(xiàn)?

預(yù)先準(zhǔn)備三個(gè)圖標(biāo)文件,用于樹型控件中顯示磁盤符號和文件夾的圖像之用。

1、窗體上添加控件如下:

組合框控件 ComboBox1,樹型控件 TreeView1,列表框控件 ListBox1,圖像列表控件 ImageList1。

選中TreeView1,設(shè)置其ImageList屬性為ImageList1。

2、設(shè)置屬性

選中圖像列表控件 ImageList1,在屬性窗口里,選中屬性Images,單擊三個(gè)小點(diǎn)按鈕,出現(xiàn)圖像集合編輯器窗口,單擊[添加按鈕],一一把準(zhǔn)備好的圖標(biāo)文件進(jìn)行添加,注意先后次序,如果不符合要求可以通過上下移動(dòng)按鈕重新改變次序。完成后單擊[確定]。

運(yùn)行圖如下:

完整代碼如下:

Imports?System.IO

Public?Class?Form1

Private?Sub?Form1_Load(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?MyBase.Load

'添加系統(tǒng)所有磁盤目錄符號

For?Each?MyDrive?As?String?In?Environment.GetLogicalDrives()

ComboBox1.Items.Add(MyDrive)

Next

'顯示第一個(gè)磁盤符號

ComboBox1.Text?=?ComboBox1.Items(0)

End?Sub

'遞歸過程添加目錄樹

Public?Sub?AddDirectory(ByVal?strFatherPath?As?String,?ByVal?strPath?As?String,?ByVal?nodeFather?As?TreeNode)

Dim?i?As?Integer

Dim?Mynode?As?New?TreeNode

'先添加本目錄

Mynode.Text?=?Strings.Replace(strPath,?strFatherPath??"\",?"",?,?1)

'為節(jié)點(diǎn)指定未被選中時(shí)顯示的圖標(biāo)

Mynode.ImageIndex?=?1

'為節(jié)點(diǎn)指定被選中時(shí)顯示的圖標(biāo)

Mynode.SelectedImageIndex?=?2

nodeFather.Nodes.Add(Mynode)

Application.DoEvents()

Try

Dim?str()?As?String?=?Directory.GetDirectories(strPath)

'遞歸遍歷該目錄的子文件夾

For?i?=?0?To?str.GetUpperBound(0)

AddDirectory(strPath,?str(i),?Mynode)

Next

Catch?ex?As?Exception

Debug.WriteLine(ex.Message)

End?Try

Mynode?=?Nothing

End?Sub

'根據(jù)給出的盤符添加目錄樹

Private?Sub?AddRootDirectory(ByVal?DiscSymbol?As?String)

Dim?Nynode?As?New?TreeNode

'先把磁盤盤符添加到樹中

TreeView1.Nodes.Clear()

Nynode.ImageIndex?=?0

Nynode.Text?=?DiscSymbol

Nynode.SelectedImageIndex?=?-1

TreeView1.Nodes.Add(Nynode)

Dim?i?As?Integer

'獲取磁盤根目錄下的文件夾

Dim?str()?As?String?=?Directory.GetDirectories(DiscSymbol??"\")

For?i?=?0?To?str.GetUpperBound(0)

'調(diào)用遞歸過程遍歷該文件夾里的所有子文件夾,并添加到樹型控件

AddDirectory(DiscSymbol,?str(i),?Nynode)

Next

Nynode?=?Nothing

End?Sub

Private?Sub?ComboBox1_SelectedIndexChanged(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?ComboBox1.SelectedIndexChanged

'根據(jù)磁盤符號的變更,顯示根目錄里的文件

ListBox1.Items.Clear()

For?Each?MyFile?As?String?In?System.IO.Directory.GetFiles(ComboBox1.Text)

ListBox1.Items.Add(MyFile)

Next

'根據(jù)磁盤符號的變更,重新顯示目錄樹

Dim?DiscSymbol?As?String

DiscSymbol?=?Microsoft.VisualBasic.Left(ComboBox1.Text,?Len(ComboBox1.Text)?-?1)

Call?AddRootDirectory(DiscSymbol)

End?Sub

'遞歸過程根據(jù)子目錄尋找上級目錄名--從而構(gòu)成完整的目錄路徑

Private?Sub?AllPath(ByVal?ThisNode?As?TreeNode,?ByRef?MyPathName?As?String)

If?ThisNode.Level??1?Then

'該節(jié)點(diǎn)層數(shù)大于1,其父節(jié)點(diǎn)不是磁盤根目錄

MyPathName?=?ThisNode.Parent.Text??"\"??MyPathName

Dim?MyNode?As?TreeNode?=?ThisNode.Parent

Call?AllPath(MyNode,?MyPathName)

Else

'該節(jié)點(diǎn)層數(shù)等于1,其父節(jié)點(diǎn)就是磁盤根目錄

MyPathName?=?ComboBox1.Text??MyPathName

End?If

End?Sub

Private?Sub?TreeView1_AfterSelect(ByVal?sender?As?System.Object,?ByVal?e?As?System.Windows.Forms.TreeViewEventArgs)?Handles?TreeView1.AfterSelect

'為了搜索選中的節(jié)點(diǎn)對應(yīng)目錄的文件,需要組成全路徑

Dim?MyAllPathName?As?String?=?TreeView1.SelectedNode.Text

Dim?MyNode?As?TreeNode?=?TreeView1.SelectedNode

If?TreeView1.SelectedNode.Level?=?0?Then

'如果選中的是根節(jié)點(diǎn)

MyAllPathName?=?ComboBox1.Text

Else

'如果選中的是非根節(jié)點(diǎn),調(diào)用遞歸過程組成全路徑

Call?AllPath(MyNode,?MyAllPathName)

MyAllPathName?=?MyAllPathName??"\"

End?If

'根據(jù)路徑,搜索文件名并顯示

ListBox1.Items.Clear()

For?Each?MyFile?As?String?In?System.IO.Directory.GetFiles(MyAllPathName)

ListBox1.Items.Add(MyFile)

Next

End?Sub

End?Class

vb獲取硬件信息的代碼

tmpstr=""

set fso=createObject("scripting.filesystemObject")

Set dc = fso.Drives

for each d in dc

If d.isReady Then

tmpstr=tmpstr "磁盤" d.DriveLetter ":" vbcrlf _

"可用空間:" (d.AvailableSpace/1024/1024/1024) " GB" vbcrlf _

"空余空間:" (d.FreeSpace/1024/1024/1024) " GB" ?vbcrlf _

"總空間大?。? (d.TotalSize/1024/1024/1024) " GB" ?vbcrlf _

"文件系統(tǒng):" d.FileSystem vbcrlf _

"驅(qū)動(dòng)器類型:" d.DriveType vbcrlf _

"是否就緒:" d.IsReady vbcrlf _

"路徑:" d.Path vbcrlf _

"根目錄:" d.RootFolder vbcrlf _

"序列號:" d.SerialNumber vbcrlf _

"共享名:" d.ShareName vbcrlf _

"卷名:" d.VolumeName vbcrlf vbcrlf

End If

Next

msgbox tmpstr


標(biāo)題名稱:vb.net獲取磁盤信息 vbnet讀取文件內(nèi)容
本文路徑:http://weahome.cn/article/hpseep.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部