Access to hard disk Volume ID

Posted on 2009-04-25
Last Modified: 2013-11-26
I am writing an application in C-Plus-Plus using Microsoft Visual Studio 2008. I want access to the Volume ID of the hard disk of the machine on which the application will run. I can get at it with a DOS command within System(), but that makes the screen flash annoyingly. Is there a function within MFC or Win32 that provides direct access?
Question by:StMike38
    LVL 5

    Accepted Solution

    this api function should help you:

    LVL 5

    Expert Comment


    Author Closing Comment

    The function GetVolumeInformation is exactly what is needed. The FoxPro documentation is a little off target, but still helpful.

    Author Comment

    Here is a little C++ snippet that is not elegant, but it works. The Volume ID shows up in Test[0].
    #include <windows.h>
        long          Test[2] ;
        char buf2[256], buf3[256] ;
        LPCTSTR lpRootPathName  = "C:\\" ;
        LPTSTR lpVolumeNameBuffer = buf2 ;
        DWORD nVolumeNameSize = 256 ;
        LPDWORD lpVolumeSerialNumber = (LPDWORD) Test ;
        LPDWORD lpMaximumComponentLength = (LPDWORD) 256 ;
        LPDWORD lpFileSystemFlags = 0 ;
        LPTSTR lpFileSystemNameBuffer = buf3 ;
        DWORD nFileSystemNameSize = 256;
        BOOL Okay = GetVolumeInformation( lpRootPathName, lpVolumeNameBuffer,
                nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength,
                lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);

    Open in new window


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Solid State (Hard) Drives aka SSD began to evolve in the computer industry recently. As the name suggests, there are no moving parts in the drives. The drive uses microchip memory store the data, as opposed to the spinning disks of a traditional HDD…
    Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now