Click here to Skip to main content
14,265,517 members

How get I the serial number hard disk windows 7 when permision user is standard

mzandi asked:

Open original thread
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
Tags: C#, Delphi, WinAPI

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




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