惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Last Week in AI
Last Week in AI
IT之家
IT之家
A
About on SuperTechFans
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
Vercel News
Vercel News
博客园 - Franky
有赞技术团队
有赞技术团队
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
量子位
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog

博客园 - 李帅斌-Memory

快速导出CSV log4net使用详解 . C# 格式化字符串 web.config中特殊字符的转译 transactionscope的使用 一些概念需要明确的解释一下 还原已清空的回收站 安装卸载Windows服务 Jquery 文章积累 Spring.NET学习——控制反转(基础篇) SqlServer2005导出数据到SqlServer2000步骤! - 李帅斌-Memory - 博客园 MSSQL2005:SQL Server 2005安装图解 网站优化-Gzip压缩 Asp.Net读取excel文件的时候 出错提示:外部表不是预期的格式 解决方案 js触发回车事件 - 李帅斌-Memory - 博客园 在Div中包含的元素移动时,触发div的onmouseout事件.解决方案! - 李帅斌-Memory - 博客园 VisualStudio用IE8调试时遇到的问题 JQuery+Ajax实现无刷新数据查询 Asp.net页面执行两遍Page_Load的解决方案
C#取硬盘序列号(-备忘-)
李帅斌-Memory · 2009-02-21 · via 博客园 - 李帅斌-Memory

using System;

using System.IO;

using System.Runtime.InteropServices;

using System.Text;

using Microsoft.Win32;

/// <summary> 
/// HardDiskVal 的摘要说明。 
/// 读取指定盘符的硬盘序列号 
/// 功能:读取指定盘符的硬盘序列号 
/// </summary> 
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

    );

/// <summary> /// 获得盘符为drvID的硬盘序列号,缺省为C /// </summary> /// <param name="drvID"></param> /// <returns></returns> 

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

    }

}