C#读取硬盘物理序列号-非管理员权限

该博客介绍了如何在C#中通过非管理员权限获取硬盘物理序列号。通过使用`System.Runtime.InteropServices`进行DllImport,调用kernel32.dll的相关API,如`CreateFile`和`DeviceIoControl`,并定义相应的结构体`STORAGE_PROPERTY_QUERY`和`STORAGE_DEVICE_DESCRIPTOR`,实现了从硬盘设备中读取序列号的功能。代码示例展示了具体实现步骤和关键函数的用法。
摘要由CSDN通过智能技术生成

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SCBLL.Comm
{
    [StructLayout(LayoutKind.Sequential)]
    internal struct STORAGE_PROPERTY_QUERY
    {
        public uint PropertyId;
        public uint QueryType;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
        public byte[] AdditionalParameters;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    internal struct STORAGE_DEVICE_DESCRIPTOR
    {
        public uint Version;
        public uint size;
        public byte DeviceType;
        public byte DeviceTypeModifier;
        public byte RemovableMedia;
        public byte CommandQueueing;
        public uint VendorIdOffset;
        public uint ProductIdOffset;
        public uint ProductRevisionOffset;
        public uint SerialNumberOffset;
        public uint BusType;
        public uint RawPropertiesLength;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x1000)]
        public byte[] RawDeviceProperties;
    }

    public class HardDisk
    {

        [DllImport("kernel32.d

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值