Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse the fsutil utility to get a disk's NTFS information
DescriptionThis example shows how to use the fsutil utility to get a disk's NTFS information in Visual Basic 6.
Keywordsfsutil, NTFS, console
CategoriesWindows, Software Engineering
 
The NTFS information includes such things as the drive's NTFS version number, number of sectors, number of free sectors, and so forth.

The program uses the ExecAndCapture function to execute the following command line and capture its output.

    fsutil fsinfo ntfsinfo c:

It displays the information returned in the txtResults text box.

 
Private Sub Form_Load()
    txtResults.Text = ExecAndCapture( _
        "fsutil fsinfo ntfsinfo c:")
    txtResults.SelStart = 0
    txtResults.SelLength = 0
End Sub
 
Function ExecAndCapture is based on a routine by Dipak Auddy. The function uses CreateProcess to execute the command and uses pipes to capture the output.
 
Public Function ExecAndCapture(ByVal cmd As String, _
    Optional ByVal start_dir As String = vbNullString) As _
    String
Const BUFSIZE         As Long = 1024 * 10
Dim hPipeRead         As Long
Dim hPipeWrite        As Long
Dim sa                As SECURITY_ATTRIBUTES
Dim si                As STARTUPINFO
Dim pi                As PROCESS_INFORMATION
Dim baOutput(BUFSIZE) As Byte
Dim result            As String
Dim lBytesRead        As Long

    With sa
        .nLength = Len(sa)
        .bInheritHandle = 1    ' get inheritable pipe
            ' handles
    End With 'SA

    If CreatePipe(hPipeRead, hPipeWrite, sa, 0) = 0 Then
        ExecAndCapture = "Error creating pipe"
        Exit Function
    End If

    With si
        .cb = Len(si)
        .dwFlags = STARTF_USESHOWWINDOW Or _
            STARTF_USESTDHANDLES
        .wShowWindow = SW_HIDE          ' hide the window
        .hStdOutput = hPipeWrite
        .hStdError = hPipeWrite
    End With 'SI
    
    If CreateProcess(vbNullString, cmd, ByVal 0&, ByVal 0&, _
        1, 0&, ByVal 0&, start_dir, si, pi) Then
        CloseHandle hPipeWrite
        CloseHandle pi.hThread
        hPipeWrite = 0
        Do
            DoEvents
            If ReadFile(hPipeRead, baOutput(0), BUFSIZE, _
                lBytesRead, ByVal 0&) = 0 Then
                Exit Do
            End If
            result = Left$(StrConv(baOutput(), vbUnicode), _
                lBytesRead)
        Loop
        CloseHandle pi.hProcess
    Else
        result = "Error creating process"
    End If

    ' To make sure...
    CloseHandle hPipeRead
    CloseHandle hPipeWrite

    ExecAndCapture = result
End Function
 
The result looks like this:

NTFS Volume Serial Number :       0x1688b54988b527df
Version :                         3.1
Number Sectors :                  0x0000000009e5b05f
Total Clusters :                  0x00000000013cb60b
Free Clusters  :                  0x0000000000983142
Total Reserved :                  0x0000000000000000
Bytes Per Sector  :               512
Bytes Per Cluster :               4096
Bytes Per FileRecord Segment    : 1024
Clusters Per FileRecord Segment : 0
Mft Valid Data Length :           0x0000000004ce0000
Mft Start Lcn  :                  0x00000000000c4fd2
Mft2 Start Lcn :                  0x00000000003e823e
Mft Zone Start :                  0x0000000000206340
Mft Zone End   :                  0x0000000000212220
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated