熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#應用:讀取指定盤符的硬盤序列號

2022-06-13   來源: .NET編程 

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


From:http://tw.wingwit.com/Article/program/net/201311/13904.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.