c#

位置:IT落伍者 >> c# >> 浏览文章

C#应用:读取指定盘符的硬盘序列号


发布日期:2021年06月07日
 
C#应用:读取指定盘符的硬盘序列号

using System;

using SystemIO;

using SystemRuntimeInteropServices;

using SystemText;

using MicrosoftWin;

namespace WjbReadOrWriteIniAndReg

{

/**////

/// 读取指定盘符的硬盘序列号

///

public class HardDiskVal

{

[DllImport(kerneldll)]

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 = ;

int retVal = ;

int a =;

int b =;

string str = null;

string str = null;

int i = GetVolumeInformation(

drvID + @:\

str

MAX_FILENAME_LEN

ref retVal

a

b

str

MAX_FILENAME_LEN

);

return retValToString();

}

public string HDVal()

{

const int MAX_FILENAME_LEN = ;

int retVal = ;

int a =;

int b =;

string str = null;

string str = null;

int i = GetVolumeInformation(

c:\\

str

MAX_FILENAME_LEN

ref retVal

a

b

str

MAX_FILENAME_LEN

);

return retValToString();

}

}

               

上一篇:C#锐利体验之第八讲 索引器与操作符重载

下一篇:c#产生随机颜色