Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting unique key

Getting unique key

Scheduled Pinned Locked Moved C#
question
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sumit7034
    wrote on last edited by
    #1

    hii I am generating key based on cpu id using following code public static string GetProcessorID() { string sProcessorID = ""; string sQuery = "SELECT ProcessorId FROM Win32_Processor"; ManagementObjectSearcher oManagementObjectSearcher = new ManagementObjectSearcher(sQuery ); ManagementObjectCollection oCollection = oManagementObjectSearcher.Get(); foreach(ManagementObject oManagementObject in oCollection ) { sProcessorID = (string)oManagementObject["ProcessorId"]; } return (sProcessorID); } But i find that the generated id is not unique. is there any other way to generate unique id based on cpu? as i want to secure my software from piracy thanks in advance

    T D 2 Replies Last reply
    0
    • S sumit7034

      hii I am generating key based on cpu id using following code public static string GetProcessorID() { string sProcessorID = ""; string sQuery = "SELECT ProcessorId FROM Win32_Processor"; ManagementObjectSearcher oManagementObjectSearcher = new ManagementObjectSearcher(sQuery ); ManagementObjectCollection oCollection = oManagementObjectSearcher.Get(); foreach(ManagementObject oManagementObject in oCollection ) { sProcessorID = (string)oManagementObject["ProcessorId"]; } return (sProcessorID); } But i find that the generated id is not unique. is there any other way to generate unique id based on cpu? as i want to secure my software from piracy thanks in advance

      T Offline
      T Offline
      TommyTomToms
      wrote on last edited by
      #2

      Have you had a look at GUID's..? They are unique (some even use them as database primary keys :) ) To generate one :

              Guid guid = new Guid();
      
              guid = Guid.NewGuid();
      
              string unique = guid.ToString();
      

      A dogged, arrogant belief in self and the childlike idealism that comes with not knowing my limits. This is my greatest blessing, my priceless attribute.

      J S 2 Replies Last reply
      0
      • T TommyTomToms

        Have you had a look at GUID's..? They are unique (some even use them as database primary keys :) ) To generate one :

                Guid guid = new Guid();
        
                guid = Guid.NewGuid();
        
                string unique = guid.ToString();
        

        A dogged, arrogant belief in self and the childlike idealism that comes with not knowing my limits. This is my greatest blessing, my priceless attribute.

        J Offline
        J Offline
        Jason C Bourne
        wrote on last edited by
        #3

        If you need a unique number that is always the same when regenerated, you can always ask a hashcode on a unique string, as long as you manage to create the same string. Here is a modified version of the previous answer to illustrate the idea: Guid guid = new Guid(); guid = Guid.NewGuid(); string unique = guid.ToString(); int uniqueInt = unique.GetHashCode();

        Jean-Christophe Grégoire

        1 Reply Last reply
        0
        • T TommyTomToms

          Have you had a look at GUID's..? They are unique (some even use them as database primary keys :) ) To generate one :

                  Guid guid = new Guid();
          
                  guid = Guid.NewGuid();
          
                  string unique = guid.ToString();
          

          A dogged, arrogant belief in self and the childlike idealism that comes with not knowing my limits. This is my greatest blessing, my priceless attribute.

          S Offline
          S Offline
          sumit7034
          wrote on last edited by
          #4

          I want to generate unique id for a particular purpose ie Generating Unique Key for a Computer for Licensing Purpose

          D 1 Reply Last reply
          0
          • S sumit7034

            I want to generate unique id for a particular purpose ie Generating Unique Key for a Computer for Licensing Purpose

            D Offline
            D Offline
            Dragonfly_Lee
            wrote on last edited by
            #5

            sumit7034 wrote:

            Unique Key for a Computer for Licensing Purpose

            GUID represents a globally unique identifier. So do not worry.

            Tan Li I Love KongFu~

            S 1 Reply Last reply
            0
            • D Dragonfly_Lee

              sumit7034 wrote:

              Unique Key for a Computer for Licensing Purpose

              GUID represents a globally unique identifier. So do not worry.

              Tan Li I Love KongFu~

              S Offline
              S Offline
              sumit7034
              wrote on last edited by
              #6

              Every time it generate a new id. i don't want this i want a unique id for a particular pc so that it don't match with the id of other computer

              D 1 Reply Last reply
              0
              • S sumit7034

                hii I am generating key based on cpu id using following code public static string GetProcessorID() { string sProcessorID = ""; string sQuery = "SELECT ProcessorId FROM Win32_Processor"; ManagementObjectSearcher oManagementObjectSearcher = new ManagementObjectSearcher(sQuery ); ManagementObjectCollection oCollection = oManagementObjectSearcher.Get(); foreach(ManagementObject oManagementObject in oCollection ) { sProcessorID = (string)oManagementObject["ProcessorId"]; } return (sProcessorID); } But i find that the generated id is not unique. is there any other way to generate unique id based on cpu? as i want to secure my software from piracy thanks in advance

                D Offline
                D Offline
                dan sh
                wrote on last edited by
                #7

                This[^] article does something similar to what you need. Might help.

                The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."

                1 Reply Last reply
                0
                • S sumit7034

                  Every time it generate a new id. i don't want this i want a unique id for a particular pc so that it don't match with the id of other computer

                  D Offline
                  D Offline
                  Dragonfly_Lee
                  wrote on last edited by
                  #8

                  I see, in this case, you can use the MAC address as the unique ID for PC. Of cource, you can also generate the license file through MD5. Everytime the app runs, check the license file firstly.

                  Tan Li I Love KongFu~

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups