10923|28

86

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

在WinCE里如何取硬盘、网卡、CPU的序列号 [复制链接]

如题,用C#如何取CE里的相关序列号?
我在论坛里找了好久,但都是在Windows XP(2000)系统里的,请高人指点,或者在CE里如何用ManagementObject或MarshalAs
只要取的一个序列号即给分

最新回复

[DllImport( "coredll.dll ")] 设备提示找不到指定的dll文件啊  详情 回复 发表于 2008-4-9 09:55
点赞 关注

回复
举报

74

帖子

0

TA的资源

禁止访问

沙发
 
提示: 作者被禁止或删除 内容自动屏蔽
 
 

回复

84

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
WinCE可以通过机器序列号确定唯一。这是ce机器的一个标准属性
 
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

4
 
机器序列号又是如何取得的?盼指教
 
 
 

回复

77

帖子

0

TA的资源

一粒金砂(初级)

5
 
这个东东GetDeviceUniqueID
 
 
 

回复

54

帖子

0

TA的资源

一粒金砂(初级)

6
 
你想获得那么多东西恐怕有点困难,在2002版本以前,设备id是没法获得的,因为系统都是oem的微软的,如果硬件本身不支持,只能是操作系统提供一个设备id,那么这样每个操作系统都是不同的,也就不叫oem了,增加了很多费用,所以那时候硬件厂商都决定不支持。
但是从200之后,微软先建议后强制厂商们支持一个叫KernelIoControl的函数,c#原型如下:
[DllImport("coredll.dll")]
private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr
  InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32
  OutputBufferSize, ref Int32 BytesReturned);
他可以获取设备id,但是这个函数本身不做任何处理,它只是把请求发给硬件
 
 
 

回复

82

帖子

0

TA的资源

一粒金砂(中级)

7
 
你可以到微软的网站上找《如何:获取设备 ID 和名称》,还有盘文章,好像是:使用 Microsoft .NET Framework检索Windows CE设备ID
 
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

8
 
我的BLOG里抄了两位前辈的取序列号的文章,去看看啊,也许对你有帮助
 
 
 

回复

68

帖子

0

TA的资源

一粒金砂(初级)

9
 
获得设备ID:
private System.ComponentModel.Container components = null;
        private static Int32 METHOD_BUFFERED = 0;
        private static Int32 FILE_ANY_ACCESS = 0;
        private static Int32 FILE_DEVICE_HAL = 0x00000101;

        private const Int32 ERROR_NOT_SUPPORTED = 0x32;
        private const Int32 ERROR_INSUFFICIENT_BUFFER = 0x7A;


        private static Int32 IOCTL_HAL_GET_DEVICEID = ((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14) | ((21) << 2) | (METHOD_BUFFERED);


        [DllImport("coredll.dll", SetLastError = true)]
        private static extern bool KernelIoControl(Int32 dwIoControlCode, IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf, Int32 nOutBufSize, ref Int32 lpBytesReturned);

        private static string GetDeviceID()
        {


            // Initialize the output buffer to the size of a Win32 DEVICE_ID structure
            byte[] outbuff = new byte[20];
            Int32 dwOutBytes;
            bool done = false;

            Int32 nBuffSize = outbuff.Length;

            // Set DEVICEID.dwSize to size of buffer.  Some platforms look at
            // this field rather than the nOutBufSize param of KernelIoControl
            // when determining if the buffer is large enough.
            //
            BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0);
            dwOutBytes = 0;


            // Loop until the device ID is retrieved or an error occurs
            while (!done)
            {
                if (KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outbuff, nBuffSize, ref dwOutBytes))
                {
                    done = true;
                }
                else
                {
                    int error = Marshal.GetLastWin32Error();
                    switch (error)
                    {
                        case ERROR_NOT_SUPPORTED:
                            throw new NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on this device", new Win32Exception(error));

                        case ERROR_INSUFFICIENT_BUFFER:
                            // The buffer wasn't big enough for the data.  The
                            // required size is in the first 4 bytes of the output
                            // buffer (DEVICE_ID.dwSize).
                            nBuffSize = BitConverter.ToInt32(outbuff, 0);
                            outbuff = new byte[nBuffSize];

                            // Set DEVICEID.dwSize to size of buffer.  Some
                            // platforms look at this field rather than the
                            // nOutBufSize param of KernelIoControl when
                            // determining if the buffer is large enough.
                            //
                            BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0);
                            break;

                        default:
                            throw new Win32Exception(error, "Unexpected error");
                    }
                }
            }

            Int32 dwPresetIDOffset = BitConverter.ToInt32(outbuff, 0x4);    // DEVICE_ID.dwPresetIDOffset
            Int32 dwPresetIDSize = BitConverter.ToInt32(outbuff, 0x8);      // DEVICE_ID.dwPresetSize
            Int32 dwPlatformIDOffset = BitConverter.ToInt32(outbuff, 0xc);  // DEVICE_ID.dwPlatformIDOffset
            Int32 dwPlatformIDSize = BitConverter.ToInt32(outbuff, 0x10);   // DEVICE_ID.dwPlatformIDBytes
            StringBuilder sb = new StringBuilder();

            for (int i = dwPresetIDOffset; i < dwPresetIDOffset + dwPresetIDSize; i++)
            {
                sb.Append(String.Format("{0:X2}", outbuff));
            }

            sb.Append("-");
            for (int i = dwPlatformIDOffset; i < dwPlatformIDOffset + dwPlatformIDSize; i++)
            {
                sb.Append(String.Format("{0:X2}", outbuff));

            }
            return sb.ToString();

        }

调用:
string strDeviceID = GetDeviceID();
MessageBox.Show(strDeviceID);
 
 
 

回复

65

帖子

0

TA的资源

一粒金砂(初级)

10
 
忘记写引用了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
using System.Security.Cryptography;
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

11
 
楼上的我在微软的网站上见过,也试过,但测试所有的机器的ID都相同,但同样谢谢你
honkerhero(孤独的流浪),你的BLOG我看过,但那不是在Compact framework环境下的C#代码
希望有经验的朋友说说你们是怎样在CE里保护自己的
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

12
 
没人知道吗
自己顶
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

13
 
再顶
 
 
 

回复

84

帖子

0

TA的资源

一粒金砂(初级)

14
 
取得硬件序列号,最好自己来写。

因为像KernelIoControl这样的函数,是MS定义的,但MS却没有实现。具体的实现是由OEM商来做的,但多数OEM并没有实现这个功能。
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

15
 
自己怎么写,楼上的可否给个思路呢(有代码更好)
 
 
 

回复

64

帖子

0

TA的资源

一粒金砂(初级)

16
 
这是个好问题.
我也是想获取到设备id,但是总是得不到,不管是哪个序列号。
现在的想法是自己维护序列号,烧到flash中去,然后把那块保护起来。
 
 
 

回复

64

帖子

0

TA的资源

一粒金砂(初级)

17
 
如何保护,请楼上的指点
 
 
 

回复

59

帖子

0

TA的资源

一粒金砂(初级)

18
 
关注
 
 
 

回复

79

帖子

0

TA的资源

一粒金砂(初级)

19
 
取得硬件ID,应该由驱动在设计时提供接口。
一般CPU、Flash都有ID,可以通过驱动读到。

自己维护一个ID也可以,只是存在哪里比较成问题,想保护就更难啦。
 
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

20
 
对头 得到FLASH 的ID
还是不错的选择地

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表