473,385 Members | 1,641 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,385 software developers and data experts.

WMI for Win32_Volume not working

I'm trying to execute this simple query:

ObjectQuery objectQuery = new ObjectQuery("Select * FROM Win32_Volume");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
ManagementObjectCollection moc = searcher.Get();
try
{
foreach (ManagementObject volume in moc)
{
Console.WriteLine("Label = " + volume["Label"]);
}
}
catch (ManagementException e)
{
Console.WriteLine(e.Message);
}

But I get an ManagementException thrown in the foreach (not on the
Console.WriteLine that follows)

The message is simply "Invalid Class" which doesn't really tell me a whole
lot.

Looking around the web, I've found a couple of pieces of code that aren't
too different from this, but nothing to explain why I would be getting this
problem.

I'm running VS.NET 2003 on Win2K Professional.

Thanks for any help anyone can give.
Nov 16 '05 #1
5 6712
pd******@hotmail.com wrote:
I'm trying to execute this simple query:

ObjectQuery objectQuery = new ObjectQuery("Select * FROM Win32_Volume");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
ManagementObjectCollection moc = searcher.Get();
try
{
foreach (ManagementObject volume in moc)
{
Console.WriteLine("Label = " + volume["Label"]);
}
}
catch (ManagementException e)
{
Console.WriteLine(e.Message);
}

But I get an ManagementException thrown in the foreach (not on the
Console.WriteLine that follows)

The message is simply "Invalid Class" which doesn't really tell me a whole
lot.

Looking around the web, I've found a couple of pieces of code that aren't
too different from this, but nothing to explain why I would be getting this
problem.

I'm running VS.NET 2003 on Win2K Professional.


Hi pd******@hotmail.com,

your code is compiling and running without problems on my machine.

Are you sure you added the reference to the System.Management.dll and
that you added

using System.Management;

to your code?

Cheers

Arne Janning
Nov 16 '05 #2
Hi,

Win32_Volume isn't availble on windows xp or earlier.
http://msdn.microsoft.com/library/de...n32_volume.asp

Ken
-----------------
<pd******@hotmail.com> wrote in message
news:97******************************@news.meganet news.com...
I'm trying to execute this simple query:

ObjectQuery objectQuery = new ObjectQuery("Select * FROM Win32_Volume");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
ManagementObjectCollection moc = searcher.Get();
try
{
foreach (ManagementObject volume in moc)
{
Console.WriteLine("Label = " + volume["Label"]);
}
}
catch (ManagementException e)
{
Console.WriteLine(e.Message);
}

But I get an ManagementException thrown in the foreach (not on the
Console.WriteLine that follows)

The message is simply "Invalid Class" which doesn't really tell me a whole
lot.

Looking around the web, I've found a couple of pieces of code that aren't
too different from this, but nothing to explain why I would be getting
this
problem.

I'm running VS.NET 2003 on Win2K Professional.

Thanks for any help anyone can give.

Nov 16 '05 #3
I had a feeling that might be the case (that's why I mentioned my OS),
though I thought it was going to be an XP-only thing.

Really, I only need one thing, the volume label. How can I get it without
the Win32_Volume WMI?

Pete

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hi,

Win32_Volume isn't availble on windows xp or earlier.
http://msdn.microsoft.com/library/de...n32_volume.asp
Ken
-----------------
<pd******@hotmail.com> wrote in message
news:97******************************@news.meganet news.com...
I'm trying to execute this simple query:

ObjectQuery objectQuery = new ObjectQuery("Select * FROM Win32_Volume");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
ManagementObjectCollection moc = searcher.Get();
try
{
foreach (ManagementObject volume in moc)
{
Console.WriteLine("Label = " + volume["Label"]);
}
}
catch (ManagementException e)
{
Console.WriteLine(e.Message);
}

But I get an ManagementException thrown in the foreach (not on the
Console.WriteLine that follows)

The message is simply "Invalid Class" which doesn't really tell me a whole lot.

Looking around the web, I've found a couple of pieces of code that aren't too different from this, but nothing to explain why I would be getting
this
problem.

I'm running VS.NET 2003 on Win2K Professional.

Thanks for any help anyone can give.


Nov 16 '05 #4
On Mon, 31 May 2004 11:57:41 GMT, <pd******@hotmail.com> wrote:
I had a feeling that might be the case (that's why I mentioned my OS),
though I thought it was going to be an XP-only thing.

Really, I only need one thing, the volume label. How can I get it without
the Win32_Volume WMI?

Pete

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hi,

Win32_Volume isn't availble on windows xp or earlier.

http://msdn.microsoft.com/library/de...n32_volume.asp


[snipped]

How about:
// GetVolumeInformation
[DllImport("kernel32.dll",
EntryPoint="GetVolumeInformation", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
public static extern int GetVolumeInformation(
[MarshalAs(UnmanagedType.LPStr)]
string lpRootPathName,
StringBuilder lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
ref int lpMaximumComponentLength,
ref int lpFileSystemFlags,
StringBuilder lpFileSystemNameBuffer,
int nFileSystemNameSize);

It gets a lot of other stuff as well but it's quick.

--
Jeff Gaines - Damerham Hampshire UK

Nov 16 '05 #5
Yeah, that's the way I went. I was hoping there was a managed method. I
really hate going outside of the managed API if possible, but I guess I
don't have a choice in this case.

Thanks.

Pete

"Jeff Gaines" <je**@nospam.co.uk> wrote in message
news:65********************************@4ax.com...
On Mon, 31 May 2004 11:57:41 GMT, <pd******@hotmail.com> wrote:
I had a feeling that might be the case (that's why I mentioned my OS),
though I thought it was going to be an XP-only thing.

Really, I only need one thing, the volume label. How can I get it without
the Win32_Volume WMI?

Pete

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hi,

Win32_Volume isn't availble on windows xp or earlier.

http://msdn.microsoft.com/library/de...-us/wmisdk/wmi

/win32_volume.asp
[snipped]

How about:
// GetVolumeInformation
[DllImport("kernel32.dll",
EntryPoint="GetVolumeInformation", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
public static extern int GetVolumeInformation(
[MarshalAs(UnmanagedType.LPStr)]
string lpRootPathName,
StringBuilder lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
ref int lpMaximumComponentLength,
ref int lpFileSystemFlags,
StringBuilder lpFileSystemNameBuffer,
int nFileSystemNameSize);

It gets a lot of other stuff as well but it's quick.

--
Jeff Gaines - Damerham Hampshire UK

Nov 16 '05 #6

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

Similar topics

2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
8
by: Hardy Wang | last post by:
Hi: Is it possible for me to create/open web application from remote machine other than port 80? And create application directly under virtual web site instead of creating a virtual directory?...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...

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.