0

Please do not unovte or close this question. I am really helpless and have no idea what to do. I have created a simple C# winForm Applicaton. I made it run only when the particular serial key of a NOrmal USB is matched. Presently, I came to know about this USB e-licenser. I want to make my program run only when this device is installed. However, I do not have idea how to deal with this device. When I use eLicenser Control Center - License Management software,I can see the following:. The software also says that the serial number of this device is 1987756 - 54406E. Can anyone please help me how should I use the USB licenser in the follwing piece of C# code?

if (ValidHD()==true)
        {
            Application.Run(new Form1());
        }
        else
        {
            resultPOP = MessageBox.Show(messagePOP);
        }

 private static bool ValidHD()
    {
        int i = 0;
        bool retData = false;
        List<String> hdSNList = new List<string>();
        ManagementObjectSearcher moSearcher = new ManagementObjectSearcher("select * from Win32_DiskDrive");
        foreach (ManagementObject wmi_HDD in moSearcher.Get())
        {
            
            hdSNList.Add(wmi_HDD["SerialNumber"].ToString());
        }

        String[] hdSN = hdSNList.ToArray();

        while (hdSN.Length>i)
        {
            if (hdSN[i] == "1987756 - 54406E.")
            {
                retData = true;
            }
            i++;
        }
        if (retData)
        {
            return true;
        }
        else
        {
            return false;
        }
        
    }
  • [How do I get information about recently connected USB device?](https://stackoverflow.com/a/54298316/7444103) => [Get the serial number of USB storage devices](https://stackoverflow.com/a/51806262/7444103) – Jimi May 17 '22 at 02:58
  • @Jimi it is not storage device. It is e-licenser. – Neww Programmerr May 17 '22 at 04:19
  • The code in the first link tells you when an USB device is inserted or removed, the code in the second link is actually meant to enumerate volumes / partitions of storage devices and return all the available details, but you of course don't need the part related to Volumes, you may just grab the serial number (in a more *constructed* way) -- Your question is: *how should I modify the following piece of code so that it runs when this device is inserted?* That's what that code is about. What's inside the license key is interpreted by a dedicated software. – Jimi May 17 '22 at 04:32
  • @Jimi I need to use USB e-licenser. – Neww Programmerr May 17 '22 at 05:43

0 Answers0