Created
October 8, 2015 17:56
-
-
Save SajjadArifGul/53bdc077541ecef46329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.Runtime.InteropServices; | |
namespace howto_disk_serial_number | |
{ | |
public partial class Form1 : Form | |
{ | |
[DllImport("kernel32.dll")] | |
private static extern long GetVolumeInformation( | |
string PathName, | |
StringBuilder VolumeNameBuffer, | |
UInt32 VolumeNameSize, | |
ref UInt32 VolumeSerialNumber, | |
ref UInt32 MaximumComponentLength, | |
ref UInt32 FileSystemFlags, | |
StringBuilder FileSystemNameBuffer, | |
UInt32 FileSystemNameSize); | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void btnGetInformation_Click(object sender, EventArgs e) | |
{ | |
string drive_letter = txtDisk.Text; | |
drive_letter = drive_letter.Substring(0, 1) + ":\\"; | |
uint serial_number = 0; | |
uint max_component_length = 0; | |
StringBuilder sb_volume_name = new StringBuilder(256); | |
UInt32 file_system_flags = new UInt32(); | |
StringBuilder sb_file_system_name = new StringBuilder(256); | |
if (GetVolumeInformation(drive_letter, sb_volume_name, | |
(UInt32)sb_volume_name.Capacity, ref serial_number, ref max_component_length, | |
ref file_system_flags, sb_file_system_name, (UInt32)sb_file_system_name.Capacity) == 0) | |
{ | |
MessageBox.Show( | |
"Error getting volume information.", | |
"Error", MessageBoxButtons.OK, | |
MessageBoxIcon.Exclamation); | |
} else { | |
lblVolumeName.Text = sb_volume_name.ToString(); | |
lblSerialNumber.Text = serial_number.ToString(); | |
lblMaxComponentLength.Text = max_component_length.ToString(); | |
lblFileSystem.Text = sb_file_system_name.ToString(); | |
lblFlags.Text = "&&H" + file_system_flags.ToString("x"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment