Verfügbarkeit von Win32_MountPoint und Win32_Volume unter Windows XP?

Aus den MSDN-Artikeln, die ich gefunden habe -http: //msdn.microsoft.com/en-us/library/aa394515 (v = VS.85) .aspx - Win32_Volume und Win32_MountPoint sind unter Windows XP nicht verfügbar.

Ich entwickle jedoch eine C # -App unter Windows XP (64 Bit) und kann diese WMI-Klassen problemlos nutzen. Benutzer meiner App werden unter Windows XP SP2 mit .NET 3.5 SP1 sein.

Googeln, ich kann nicht feststellen, ob ich mich darauf verlassen kann oder nicht. Bin ich auf meinem System aufgrund einer oder mehrerer der folgenden Ursachen erfolgreich: - Windows XP Service Pack 2? - Visual Studio 2008 SP1 wurde installiert? - .Net 3.5 sp1?

Sollte ich etwas anderes als WMI verwenden, um die Volume- / Mountpoint-Informationen abzurufen?

Below ist ein Beispielcode, der funktioniert ...

    public static Dictionary<string, NameValueCollection> GetAllVolumeDeviceIDs()
    {
        Dictionary<string, NameValueCollection> ret = new Dictionary<string, NameValueCollection>();

        // retrieve information from Win32_Volume
        try
        {
            using (ManagementClass volClass = new ManagementClass("Win32_Volume"))
            {
                using (ManagementObjectCollection mocVols = volClass.GetInstances())
                {
                    // iterate over every volume
                    foreach (ManagementObject moVol in mocVols)
                    {
                        // get the volume's device ID (will be key into our dictionary)                            
                        string devId = moVol.GetPropertyValue("DeviceID").ToString();

                        ret.Add(devId,  new NameValueCollection());

                        //Console.WriteLine("Vol: {0}", devId);

                        // for each non-null property on the Volume, add it to our NameValueCollection
                        foreach (PropertyData p in moVol.Properties)
                        {
                            if (p.Value == null)
                                continue;
                            ret[devId].Add(p.Name, p.Value.ToString());
                            //Console.WriteLine("\t{0}: {1}", p.Name, p.Value);
                        }

                        // find the mountpoints of this volume
                        using (ManagementObjectCollection mocMPs = moVol.GetRelationships("Win32_MountPoint"))
                        {
                            foreach (ManagementObject moMP in mocMPs)
                            {
                                // only care about adding directory
                                // Directory prop will be something like "Win32_Directory.Name=\"C:\\\\\""
                                string dir = moMP["Directory"].ToString();

                                // find opening/closing quotes in order to get the substring we want
                                int first = dir.IndexOf('"') + 1;
                                int last = dir.LastIndexOf('"');
                                string dirSubstr = dir.Substring(first , last - first);

                                // use GetFullPath to normalize/unescape any extra backslashes
                                string fullpath = Path.GetFullPath(dirSubstr);

                                ret[devId].Add(MOUNTPOINT_DIRS_KEY, fullpath);

                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Problem retrieving Volume information from WMI. {0} - \n{1}",ex.Message,ex.StackTrace);
            return ret;
        }

        return ret;

    }

Antworten auf die Frage(4)

Ihre Antwort auf die Frage