读硬盘序列号:
using System;
using System.Runtime.InteropServices;
namespace ArLi.CommonPrj
{
public class getvol
{
[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 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");
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.txtharddisk.Text = GetVolOf("c");
}
本文介绍了一个使用C#和P/Invoke技术调用Windows API的方法,通过该方法可以获取指定驱动器的序列号,并以十六进制字符串的形式返回。此功能对于需要识别不同硬件设备的应用程序特别有用。
1814

被折叠的 条评论
为什么被折叠?



