日期:2014-05-18 浏览次数:20943 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace haha
{
    public class haha
    {
        [System.Runtime.InteropServices.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
          );
        //此函数没有用,暂时没有删除
        public  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");
        }
        public string[] GetMoc()
        {
            string[] str = new string[2];
            
            ManagementClass mcHD = new ManagementClass("win32_logicaldisk");
            ManagementObjectCollection mocHD = mcHD.GetInstances();
            foreach (ManagementObject m in mocHD)
            {
                if (m["DeviceID"].ToString() == "C:")
                {
                    str[1] = m["VolumeSerialNumber"].ToString();
                    break;
                }
            }
            return str;
        }
    }
}