473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

C#.net volume label

Hi,

Can anyone provide an example of getting a hard disk/cdrom volume label in
C#.net?

Thanks in advance,
Eddie
Nov 16 '05 #1
1 7597
See inline--
using System;
using System.Collections;
using System.Management;

namespace HardDriveSample1
{
class HardDrive
{
private string model = null;
private string type = null;
private string serialNo = null;

public string Model
{
get {return model;}
set {model = value;}
}

public string Type
{
get {return type;}
set {type = value;}
}

public string SerialNo
{
get {return serialNo;}
set {serialNo = value;}
}
}

class TestProgram
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ArrayList hdCollection = new ArrayList();

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

foreach(ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
// hd.Model = wmi_HD["Model"].ToString();
// hd.Type = wmi_HD["InterfaceType"].ToString();

hdCollection.Add(hd);
}

searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

int i = 0;
foreach(ManagementObject wmi_HD in searcher.Get())
{
// get the hard drive from collection
// using index
HardDrive hd = (HardDrive)hdCollection[i];

// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
hd.SerialNo = "None";
else
hd.SerialNo = wmi_HD["SerialNumber"].ToString();

++i;
}

// Display available hard drives
foreach(HardDrive hd in hdCollection)
{
Console.WriteLine("Model\t\t: " + hd.Model);
Console.WriteLine("Type\t\t: " + hd.Type);
Console.WriteLine("Serial No.\t: " + hd.SerialNo);
Console.WriteLine();
}

// Pause application
Console.WriteLine("Press [Enter] to exit...");
Console.ReadLine();
}
}
}

--HTH
Peter
"Eddie" <ed***@idirect.com> wrote in message
news:u1**************@TK2MSFTNGP11.phx.gbl...
Hi,

Can anyone provide an example of getting a hard disk/cdrom volume label in
C#.net?

Thanks in advance,
Eddie

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob Greschke | last post by:
....the name for a drive (hard or removable) that shows up when, for example, a USB flash drive is recognized by the system. I don't know if this shows up somewhere in Linux. Can this be set...
1
by: Trevor | last post by:
Also posted in general ASP.NET forum. System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. I have hit a problem for which I can find no solutions. Has...
8
by: Dmitry Klymenko | last post by:
Do exists a way to detect a volume label of a disk? I've found the way to do this using WMI (System.Management) or winapi function. The second solution is principal non-portable in future, the first...
2
by: Eddie | last post by:
Hi, Anyone know how to get a Drive's Volume Label using vb.net? Thanks in advance. Eddie
16
by: Basil Fawlty | last post by:
Hi everyone, I have an assignment, to create a simple VB program that computes the volume of a cylinder. The Form is pretty simple, it has a label and text box for base radius, another for height...
6
by: Steve Marshall | last post by:
Hi all, I have an application that can use many different compact-flash cards as storage for different jobs the client is working on. I have added a function to erase all files from a flash...
4
by: herc | last post by:
My objective is to get the "label" information for the different volumes that are mounted. I want to display the same information as Windows Explorer. I wrote this test code with gets me the...
4
by: Dachshund Digital | last post by:
Enable Volume Compression? On NTFS volume?
7
by: sumanta123 | last post by:
Dear Sir when i am getting the value from properties file the the path showing http://127.0.0.1:81/help/Subject of Issue.txt which is right. But in jsp in try block when pass SubjectofIssue path...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.