473,386 Members | 1,823 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,386 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 7604
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.