当permision用户成为标准用户时,如何获得序列号硬盘窗口7 [英] How get I the serial number hard disk windows 7 when permision user is standard

查看:179
本文介绍了当permision用户成为标准用户时,如何获得序列号硬盘窗口7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i want protect of my application .so i read serial number hard drive and compare.  the application  has good result in mode administrator user but it has bad result in mode standard user.
i wrote my application with c#.but for read serial number hard i used of  a dll file  that i wrote with delphi. 
<pre>hDevice := CreateFile( ''\\.\PhysicalDrive0:'', GENERIC_READ or GENERIC_WRITE ,
        FILE_SHARE_READ or FILE_SHARE_WRITE , nil, OPEN_EXISTING, 0, 0 );


在标准用户模式下,此行代码返回错误.

我尝试过的事情:


this line of code in mode standard user return error.

What I have tried:

i try use of .net. so i using of WMI class(Win32_DiskDrive) but this method has result bad  in mode standard user too.
private string getserial()
        {
            string SerialNumber = "";
            string dataForSerial = string.Empty;
            
                        ManagementObjectSearcher Finder = new ManagementObjectSearcher("Select * from Win32_OperatingSystem");
            string Name = "";
            
            foreach (ManagementObject OS in Finder.Get()) Name = OS["Name"].ToString();

            //Name = "Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1"

            int ind = Name.IndexOf("Harddisk") + 8;
            int HardIndex = Convert.ToInt16(Name.Substring(ind, 1));
            Finder = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE Index=" + HardIndex);
            foreach (ManagementObject HardDisks in Finder.Get())
                foreach (ManagementObject HardDisk in HardDisks.GetRelated("Win32_PhysicalMedia"))
                    SerialNumber = HardDisk["SerialNumber"].ToString();

            // SerialNumber = dataForSerial;
          
            return SerialNumber;
        }
please help me. thank you

推荐答案

在此处查看答案:
See answer here: c# - Serial number of Hard Disk or Hard Drive - Stack Overflow[^]


同样,您现有的代码不是之所以起作用,是因为它对WMI中的数据布局方式做出了非常糟糕的假设,并且无法可靠地返回启动驱动器".

同样,您再次假设每个驱动器甚至都有一个序列号.事实并非如此.

如何尝试在具有虚拟硬盘驱动器的虚拟机上获取序列号?物理驱动器不存在.甚至更好的是,即使有一个,由同一映像制成的多台机器都可以具有相同的序列号!没想到吗?

请勿将硬盘驱动器序列号用作识别系统的唯一钥匙".根本不可靠.
Again, you''re existing code isn''t going to work because it makes very bad assumptions about how the data is laid out in WMI and cann''t reliably return the "boot drive".

Also, again, you''re making the assumption that every drive even has a serial number. That''s not the case.

How about trying to the get the serial number on a virtual machine with a virtual hard drive? The physical drive doesn''t exist. Even better, multiple machines made from the same image can all have the same serial number, if there even is one! Didn''t think about that, did you?

DO NOT use the hard drive serial number as your only "key" to identify the system. It''s not reliable at all.


这篇关于当permision用户成为标准用户时,如何获得序列号硬盘窗口7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆