Get information on logical disk in VB

zhaozj2021-02-08  206

We sometimes need some information for logical disks in the system, such as disk scroll, disk serial number, space size, remaining space, etc., which are clearly unable to obtain functions provided by VB. However, with the support of the VB on the Windows API function, use the GetVolumeInformation and getDiskFreespace, we can easily get information about the disk.

Let's talk about these two functions. The GetVolumeInformation function is used to obtain information related to a disk volume, including the disk scroll, the serial number of the disk, "/" and "/" in the full path of the file "/" and the name of the file system and the file system Some features. The GetDiskFreespace function is used to obtain information related to a disk organization, as well as the capacity of the remaining space, including the total cluster number on the disk, the number of remaining clusters, the number of sectors in a cluster, and the number of bytes in one sector.

Next, look at the specific example.

Enter VB, add a driver list box (DriveStbox) and a list box (Listbox) on the form, then add the following script:

Option expedition

Private Declare Function GetVolumeInformation

LIB "kernel32" alias

GetVolumeInformationa (Byval LPROOTPATHNAME AS)

String, ByVal LPVoluMenameBuffer AS

String, Byval NVoluMenamesize As Long,

LPVOLUMESERIALNUMBER AS Long,

LPMAXIMUMComponentlength as long,

Lpfilesystemflags as long, byval

LPFILESYSTEMNAMEBUFFER AS STRING,

BYVAL NFILESYSTEMNAMESIZE As long

Private Declare Function GetDiskFreespace

LIB "kernel32" Alias ​​"getDiskFreespacea"

(Byval LPROOTPATHNAME AS STRING, LPSECTORSPERCLUSTER

As Long, LPBYTESPERSECTOR As Long,

LPNumberoffreeClusters as long,

LPTOTOTAALNUMBEROFCLUSTERS AS Long AS Long

Private const fs_case_is_preserved = & h2

Private const fs_case_sensitive = & h1

Private const fs_unicode_stored_on_

Disk = & h4

Private const fs_persistent_acls = & h8

Private const fs_file_compression = & h10

PRIVATE const fs_vol_is_compressed =

& H8000

Private sub Drive1_change ()

DIM Volume as string, sysname as string

DIM Serialnum as long, sysflags as long,

ComponentLength As Long, RES As Long

Dim SectorsperCluster As Long, Bytespersector

As Long, NumberoffreeClustors AS

Long, TotalNumberofclustors As Longdim FreeBytes As Long, Totalbytes As long,

Percentfree As Long, DL As Long

Dim Drvname As String

List1.clear

Volume = String (256, 0)

Sysname = String (256, 0)

DRVNAME = Left (drive1.drive, 2) & "/"

Res = GetVolumeInformation (drvname,

Volume, 255, serialnum, _

ComponentLength, Sysflags, Sysname, 255)

IF res = 0 THEN

List1.additem "Cannot get disk information"

Else

List1.additem "Volume:" & Trim (Volume)

List1.additem "Serial Number:" & Serialnum

List1.additem "ingredient length:" & ComponentLength

List1.additem file system: "& Trim (sysname)

DL = GetDiskFreespace (drvname,

SectorsperCluster, Bytespersector,

NumberoffreeClustors, TotalNumberOfClustors

List1.additem "The number of sectors per cluster:"

& Format (SectorsperCluster, "#, 0")

List1.additem "Number of bytes per area:"

& Format (Bytespersector, "#, 0")

List1.additem "total cluster number:"

& Format (TotalNumberofclustors, "#, 0")

List1.additem "Remaining Clusters:"

& Format (NumberoffreeClustors, "#, 0")

Totalbytes = TotalNumberOfClustors *

SectorsperCluster * bytespersector

List1.additem "total byte number:

"& Format (Totalbytes," #, 0 ")

FreeBytes = NumberoffreeClustors

* SectorsperCluster * bytespersector

List1.additem "Remaining bytes:"

& Format (FreeBytes, "#, 0")

IF sysflags and fs_case_is_preserved then

List1.additem "file name size records on file system"

END IF

IF sysflags and fs_case_sensitive the

List1.additem "file name to be case sensitive"

END IF

IF sysflags and fs_unicore_stored_

ON_DISK THEN

List1.additem "File Name Save as Unicode Format"

END IF

IF sysflags and fs_persistent_aclsim

List1.additem "File System Support Document Access

Control List (ACL) Security Mechanism "END IF

IF sysflags and fs_file_compression then

List1.additem "file system supports file compression in file"

END IF

IF sysflags and fs_vol_is_compressed the

List1.additem "The entire disk volume is compressed"

END IF

END IF

End Sub

Private sub flow_load ()

Call drive1_change

End Sub

After running, select the different drive in the Drive List box, and the corresponding information of the drive will be displayed. The above procedures run in VB5.0, VB6.0, and Windows 98.

Reprinted from Computer World Daily (Text / Strict Winter)

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

New Post(0)