[DllImport("kernel32.dll")]
public  static extern int  GetVolumeInformation(string  lpRootPathName,string  lpVolumeNameBuffer,int  nVolumeNameSize,int  lpVolumeSerialNumber,int  lpMaximumComponentLength,int  lpFileSystemFlags,string  lpFileSystemNameBuffer,int  nFileSystemNameSize);

解决方案 »

  1.   

    补充:如果是取得逻辑序列号(Format产生的那个),用WMI就可以,在引用中,添加system.mangement以后。
    using System.Management;
    .....
    ManagementObject m_objDisk = new ManagementObject( "win32_logicaldisk.deviceid=\"c\"");
    string strSN = (string)m_objDisk.GetPropertyValue( "VolumeSerialNumber ");如果要取得物理分区号,看这个帖子:
    关于硬盘序列号,高手请留步啊. (之一)
    http://expert.csdn.net/Expert/TopicView3.asp?id=1143107
      

  2.   

    System.ManagementManagementObject 或 ManagementClass:分别为单个管理对象或类。 
    ManagementObjectSearcher:用于根据指定的查询或枚举检索 ManagementObject 或 ManagementClass 对象的集合。 
    ManagementEventWatcher:用于预订来自 WMI 的事件通知。 
    ManagementQuery:用作所有查询类的基础。 获取硬盘ID
    String HDid;
    ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");
    ManagementObjectCollection moc = cimobject.GetInstances();
    foreach(ManagementObject mo in moc)
    {
     HDid = (string)mo.Properties["Model"].Value; MessageBox.Show(HDid  ); 
    }
      

  3.   

    哇呀呀~~~ 受不了哩,班班的出错了,提示就三个字“找不到”,晕,我用api 写一个吧:using System;
    using System.Runtime.InteropServices;namespace ArLi.CommonPrj {
    public class getvol{ [DllImport("kernel32.dll")]
    public  static extern int GetVolumeInformation(
    string  lpRootPathName,
    string  lpVolumeNameBuffer,
    int  nVolumeNameSize,
    ref int  lpVolumeSerialNumber,
    int  lpMaximumComponentLength,
    int  lpFileSystemFlags,
    string  lpFileSystemNameBuffer,
    int  nFileSystemNameSize
    ); public static string getvolOf(string DrvID){
    const int MAX_FILENAME_LEN = 256;
    int RetVal = 0;
    int a =0;
    int b =0;
    string str1 = null;
    string str2 = null;


    int i = GetVolumeInformation(
    DrvID + @":\",
    str1,
    MAX_FILENAME_LEN,
    ref RetVal,
    a,
    b,
    str2,
    MAX_FILENAME_LEN); return RetVal.ToString("x");
    }
    }
    }
    使用方法MessageBox.Show(ArLi.CommonPrj.getvol.getvolOf("C"));够简单吧
      

  4.   

    请教班班,你的ManagementPath 在哪能找到资料,我以前好象见过,但没注意,好后悔ing。。