当前位置: 移动技术网 > IT编程>开发语言>c# > C#实现读取指定盘符硬盘序列号的方法

C#实现读取指定盘符硬盘序列号的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#实现读取指定盘符硬盘序列号的方法。分享给大家供大家参考,具体如下:

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();
}
}

更多关于c#相关内容感兴趣的读者可查看本站专题:《c#窗体操作技巧汇总》、《c#常见控件用法教程》、《winform控件用法总结》、《c#程序设计之线程使用技巧总结》、《c#操作excel技巧总结》、《c#中xml文件操作技巧汇总》、《c#数据结构与算法教程》、《c#数组操作技巧总结》及《c#面向对象程序设计入门教程

希望本文所述对大家c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网