如何获取服务器端的硬盘号,谢谢

解决方案 »

  1.   

    我手头的资料:需要使用.net Framwork里面System.Management名字空间下提供的类来实现.
    using System;
    using System.Management;
    using System.Collections;
    using System.Collections.Specialized; 
    namespace ACE_Console
    {
           class ACE_Console
           {
                  [STAThread]
                  static void Main(string[] args)
                  {
                         StringCollection propNames = new StringCollection();
                         ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
                         PropertyDataCollection  props = driveClass.Properties;
                         foreach (PropertyData driveProperty in props) 
                         {
                                propNames.Add(driveProperty.Name);
                         }
                          int idx = 0;
                        ManagementObjectCollection drives = driveClass.GetInstances();
                         foreach (ManagementObject drv in drives) 
                         { 
                                Console.WriteLine(" Drive({0}) Properties ", idx+1);
                                foreach (string strProp in propNames)
                                {
                                       Console.WriteLine("Property: {0}, Value: {1}", strProp, drv[strProp]);
                                }
                         }
                  }
           }
    }     
     
      

  2.   

    .net Framework SDK自带的帮助里有获得逻辑硬盘大小的代码:
    [C#]using System;using System.Management;             // This example demonstrates getting information about a class using the ManagementClass objectclass Sample_ManagementClass{       public static int Main(string[] args)        {              ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");              diskClass.Get();              Console.WriteLine("Logical Disk class has " + diskClass.Properties.Count + " properties");              return 0;       }}                                 
     
      

  3.   

    [vb]
    Imports SystemImports System.Management        // This example demonstrates getting information about a class using the ManagementClass Class Sample_ManagementClass
    Overloads Public Shared Function Main(args() As String) As IntegerDim diskClass As New ManagementClass("Win32_LogicalDisk")diskClass.Get()Console.WriteLine(("Logical Disk class has " & diskClass.Properties.Count.ToString() & " properties"))Return 0End FunctionEnd Class
      

  4.   

    http://blog.csdn.net/iwebsms/archive/2004/10/06/126397.aspx
      

  5.   

    参考--通过WMI获得硬盘和CPU的物理序列号:
    http://blog.csdn.net/iwebsms/archive/2004/10/06/126397.aspx
      

  6.   

    硬盘序列号的类using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;
    using Microsoft.Win32;namespace Wjb.ReadOrWriteIniAndReg
    {
    /// <summary>
    /// HardDiskVal 的摘要说明。
    /// 读取指定盘符的硬盘序列号
    /// 功能:读取指定盘符的硬盘序列号
    /// </summary>
    public class HardDiskVal
    {
    [DllImport("kernel32.dll")]
    private static extern int GetVolumeInformation(
    string lpRootPathName,
    string lpVolumeNameBuffer,
    int nVolumeNameSize,
    ref int lpVolumeSerialNumber,
    int lpMaximumComponentLength,
    int lpFileSystemFlags,
    string lpFileSystemNameBuffer,
    int nFileSystemNameSize
    );
    /// <summary>
    /// 获得盘符为drvID的硬盘序列号,缺省为C
    /// </summary>
    /// <param name="drvID"></param>
    /// <returns></returns>
    public string HDVal(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();
    }
    public string HDVal()
    {
    const int MAX_FILENAME_LEN = 256;
    int retVal = 0;
    int a =0;
    int b =0;
    string str1 = null;
    string str2 = null;
    int i = GetVolumeInformation(
    "c:\\",
    str1,
    MAX_FILENAME_LEN,
    ref retVal,
    a,
    b,
    str2,
    MAX_FILENAME_LEN
    );
    return retVal.ToString();
    }

    }