Click here to Skip to main content
14,269,801 members
Rate this:
Please Sign up or sign in to vote.
See more:
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
Posted
Updated 2-Jun-19 21:54pm
Comments
phil.o 2-Jun-19 7:59am
   
Repost of Run command createfile win32 as a standard user[^]
Dave Kreskowiak's answer may not be what you expected, but here is the fact: accessing raw devices like you are trying to do requires admin's privileges, for security reasons. Moreover, trying to protect your application by relying on hard drive's serial number is not an universal solution which will work in any case: some installations do not set any serial number on the hard drive. Not to mention that a C# application can be reverse-engineered in a matter of seconds, for anyone motivated enough to crack your application.
Dave Kreskowiak 3-Jun-19 18:06pm
   
I just tried a test of your scheme. My work laptop returned a specific serial number. I then checked my work desktop and it returned a serial number that was a little different. OK, no big deal.

I have a dozen virtual machines running on the desktop and checked each one of those. The Windows 7 VMs returned two different serial numbers, though one of them was the same of the desktop machine. The Windows 10 VMs all returned the same serial number. Better yet, they returned the exact same serial number my laptop returned!

Basing your scheme on the hard drive serial number will not work.
mzandi 8-Jun-19 0:49am
   
i want know why result wmi is deffrent in mode standard and administrator user in windows 7
Rate this:
Please Sign up or sign in to vote.

Solution 3

Given the caveats in Solutions 1 and 2 above, you can easily get the serial no using MS-DOS. Run a Shell() and collect the stdout using a command like
dir c:\. 2>nul: | Find "Volume Serial Number"


The result will look like
Volume Serial Number is D078-97C2
   
Comments
MadMyche 3-Jun-19 9:53am
   
The poster is looking for the Hard Drive Serial number, not the Volume Serial Number.
The Volume SN is unreliable: it can be changed, is not unique, and can even have 2 instances with the same value concurrently on a machine.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100