Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

WMI for Win32_Volume not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
- 31 May 2004 05:09 GMT
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.
Arne Janning - 31 May 2004 05:51 GMT
> I'm trying to execute this simple query:
>
[quoted text clipped - 25 lines]
>
> I'm running VS.NET 2003 on Win2K Professional.

Hi pdavis68@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
Ken Tucker [MVP] - 31 May 2004 11:56 GMT
Hi,

       Win32_Volume isn't availble on windows xp or earlier.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win3
2_volume.asp


Ken
> I'm trying to execute this simple query:
>
[quoted text clipped - 28 lines]
>
> Thanks for any help anyone can give.
- 31 May 2004 12:57 GMT
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

> Hi,
>
>         Win32_Volume isn't availble on windows xp or earlier.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win3
2_volume.asp


> Ken
> > I'm trying to execute this simple query:
[quoted text clipped - 29 lines]
> >
> > Thanks for any help anyone can give.
Jeff Gaines - 31 May 2004 14:02 GMT
>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.
[quoted text clipped - 9 lines]
>>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win3
2_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.

Signature

Jeff Gaines - Damerham Hampshire UK

- 31 May 2004 14:26 GMT
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

> >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.
[quoted text clipped - 29 lines]
>
> It gets a lot of other stuff as well but it's quick.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.