[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

Access to hard disk Volume ID

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?
0
StMike38
Asked:
StMike38
  • 2
  • 2
1 Solution
 
louislietaerCommented:
this api function should help you:

GetVolumeInformation
0
 
louislietaerCommented:
0
 
StMike38Author Commented:
The function GetVolumeInformation is exactly what is needed. The FoxPro documentation is a little off target, but still helpful.
0
 
StMike38Author Commented:
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

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now