2

I try to find a unique ID, which will be the same as the virtual machine and the main machine.

I tried using a monitor ID, bios number, but they can repeat for different end users.

using (ManagementObjectSearcher monitorSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor"))
{
    foreach (ManagementObject monitor in monitorSearcher.Get())
    {
        String MonitorName = monitor["Name"].ToString();
        String MonitorId = monitor["DeviceId"].ToString();

        Console.WriteLine("Monitor name: {0}", MonitorName);
        Console.WriteLine("Monitor id:   {0}", MonitorId);
    }
}

ManagementClass managementClass = new ManagementClass("Win32_BIOS");
ManagementObjectCollection instances = managementClass.GetInstances();
foreach (ManagementBaseObject instance in instances)
{
    string version = instance.Properties["SMBIOSBIOSVersion"].Value.ToString();
    
    Console.WriteLine("The version is :" + version.ToString());
}

I read a lot and browsed various topics and forums, but nowhere can I find information or is it possible at all? Maybe there is at least one serial number which will be repeated on the main machine as well as on the virtual one?

janw
  • 8,758
  • 11
  • 40
  • 62
adam
  • 179
  • 2
  • 12
  • What are you trying to achieve? What kind of VMs are we talking about? VMware? VirtualBox? Something else? – Fildor May 14 '19 at 06:30
  • All of these VMware , VirtualBox etc. I try to find the same on the main and virtual machine. Which is some hardware ID. And that's the same. And + noone of end users can get the same ID. – adam May 14 '19 at 06:33
  • So you are looking for a solution that's vendor-agnostic. It shall work for VMware, VB, whatnot ... Do VMs "know" they are a VM? Do you have administrative freedoms like giving them machine-names? – Fildor May 14 '19 at 06:36
  • No, I do not have the option of naming them. This is a solution for independent end users. I am looking for a parameter (Hardware ID) which will be indent to the main machine running + identical for all virtual machines running on it. – adam May 14 '19 at 06:41
  • Fun-Story from the trenches: We once tried to identify hardware by a serial-number of a certain chip it was using. We found the "serial-number" to be identical on _each and every_ of them. So if you happen to find something, better use a combination of factors. – Fildor May 14 '19 at 06:42
  • Yes, I thought the ID of the monitor is different for everyone but it turned out to be repeatable :(. – adam May 14 '19 at 06:44
  • 1
    The problem here is, while it is quite easy to figure out if you are on a VM, the whole point of a VM is mostly to have a sandbox with no punchholes to the host whatsoever. Without any assumptions that would simplify the task, like shared network adapters with host, or the like, I don't think it will be all too straight-forward. – Fildor May 14 '19 at 06:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/193306/discussion-between-adam-and-fildor). – adam May 14 '19 at 06:48
  • So, naturally, the next question would be: what are you trying to achieve? What do you want to use the information for and can you perhaps find another solution, that will be way easier? – Fildor May 14 '19 at 06:49
  • What do I try to achieve? I want the user who bought the license for the main computer to use the program also on virtual machines that are created on the main machine for which the license is purchased. That is why I try to find a common point to which I will be able to refer. – adam May 14 '19 at 06:54
  • I see. Let me think about that. I also upvoted, so this question gets more attention. Will be interested in the solution if someone has an idea. – Fildor May 14 '19 at 06:57

0 Answers0