当前位置:主页>net>文章内容
C#应用:读取指定盘符的硬盘序列号
来源: 作者: 发布时间:2007-04-05  

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;

namespace Wjb.ReadOrWriteIniAndReg
{
/**////
/// 读取指定盘符的硬盘序列号
///
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
);
/**////
/// 获得盘符为drvID的硬盘序列号,缺省为C
///
///
///
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();
}
}


 
上一篇:ASP.NET 2.0移动开发入门之使用模拟器   下一篇:C#应用:获取cpu序列号,硬盘ID,网卡MAC地址
 
  相关文章
·ASP.NET 2.0移动开发入门之使用模拟器
·C#应用:获取cpu序列号,硬盘ID,网卡MAC
·ASP.NET技巧:投票结果的图片进度条显
·漫谈Ajax在ASP.Net中的使用
·用.NET 2.0压缩/解压功能处理大型数据
·ASP.NET技巧:將datagrid控件內容輸出
·ASP.NET实现文件的在线压缩和解压缩
·介绍几个ASP.NET中容易忽略但却很重要
·ASP.NET入门随想之检票的老太太
·VS2005和ASP.NET2.0中使用强类型数据
·第一次用.net2.0 LOGIN登陆控件的困惑
·ASP.NET2.0服务器控件之自定义状态管理
 
【关闭窗口】
推荐本站资源
最新文章