C#实现读取指定盘符硬盘序列号的方法
作者:wangchao 时间:2023-05-23 15:06:39
本文实例讲述了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#,硬盘序列号
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#实现的Win32控制台线程计时器功能示例
2022-12-19 20:29:20
java格式化数字操作 NumberFormat及DecimalFormat
2023-02-23 22:03:23
![](https://img.aspxhome.com/file/2023/6/116176_0s.png)
浅谈Synchronized和Lock的区别
2023-10-26 04:28:33
Android自定义顶部标题栏
2023-02-21 19:03:47
![](https://img.aspxhome.com/file/2023/7/109167_0s.jpg)
C#字符串内存分配与驻留池学习分享
2022-07-02 12:11:29
Java之策略模式比较器案例讲解
2021-12-25 22:24:32
springboot框架阿里开源低代码工具LowCodeEngine
2022-09-01 09:40:41
![](https://img.aspxhome.com/file/2023/7/131887_0s.png)
SpringBoot详细讲解静态资源导入的实现
2023-07-26 13:23:21
![](https://img.aspxhome.com/file/2023/8/57728_0s.png)
Java中左移和右移问题图文详解
2023-02-14 15:44:05
![](https://img.aspxhome.com/file/2023/3/64113_0s.png)
Java背包问题求解实例代码
2023-10-05 06:20:33
C#/Java连接sqlite与使用技巧
2021-07-10 08:34:05
创建Android守护进程实例(底层服务)
2021-11-12 01:37:09
![](https://img.aspxhome.com/file/2023/7/139357_0s.jpg)
springmvc处理模型数据Map过程解析
2022-04-24 01:06:01
![](https://img.aspxhome.com/file/2023/8/129278_0s.png)
Android MediaPlayer 播放音频的方式
2021-09-07 07:27:09
Android判断当前App是在前台还是在后台
2022-09-20 10:37:49
spring-boot @Component和@Bean的区别详解
2023-06-28 16:10:36
WPF弹出自定义窗口的方法
2023-10-18 20:52:04
c#基于NVelocity实现代码生成
2023-06-03 14:46:18
![](https://img.aspxhome.com/file/2023/8/113828_0s.png)
java新特性之for循环最全的用法总结
2022-07-08 22:14:51
数组实现Java 自定义Queue队列及应用操作
2023-11-28 09:11:13
![](https://img.aspxhome.com/file/2023/0/60380_0s.png)