Virtual or Physical Network Adapter detection?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Virtual or Physical Network Adapter detection?

Post by DataLife » 04 Feb 2023, 19:27

This code will give me all the network adapters on my pc.

On my pc I have 2 physical adapters and several virtual adapters.

How can I modify the code to tell me which are physical and which are virtual?

Code: Select all

objWMIService := ComObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
  colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
  while colItems[objItem]
  MsgBox % objItem.Description[0]
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.


User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: Virtual or Physical Network Adapter detection?

Post by DataLife » 05 Feb 2023, 09:46

malcev wrote:
05 Feb 2023, 05:52
viewtopic.php?p=505148#p505148
?
The code from that thread returns exactly this on my computer.
Ethernet
Wi-fi

Code from the opening post of this thread
Returns this on my computer...
Intel(R) Dual Band Wireless-AC 8260
Hyper-V Virtual Ethernet Adapter #2
VMware Virtual Ethernet Adapter for VMnet1
VMware Virtual Ethernet Adapter for VMnet8
Hyper-V Virtual Ethernet Adapter
Hyper-V Virtual Ethernet Adapter #3
Hyper-V Virtual Ethernet Adapter #4
WireGuard Tunnel

I need to know if the adapters in this list are Virtual or Physical
I can't just look for Virtual in the description because not all virtual adapters have Virtual in the description.
Last edited by DataLife on 05 Feb 2023, 09:59, edited 1 time in total.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Virtual or Physical Network Adapter detection?

Post by malcev » 05 Feb 2023, 09:51

Each code can return all this properties
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968170(v=vs.85)
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapterconfiguration
I suggest You to test properties like id, guid from this 2 classes to find identical ids.

User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: Virtual or Physical Network Adapter detection?

Post by DataLife » 05 Feb 2023, 10:20

malcev wrote:
05 Feb 2023, 09:51
Each code can return all this properties
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968170(v=vs.85)
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapterconfiguration
I suggest You to test properties like id, guid from this 2 classes to find identical ids.
I have been trying to find the answer for several hours and had already read and read both of those suggestions plus much, much other stuff. Which is the problem. I have no idea what I am looking at. I can only modify the code I already found in this forum.

I found this...boolean Virtual... under MSFT_NetAdapter class but it does not help me.
I am using Ipaddress := objItem.IPAddress[0] using Win32_NetworkAdapterConfiguration to get list of adapters that have an ip address, then I need to know which are virtual and which are physical.

Code: Select all

objWMIService := ComObjGet("winmgmts:\\.\root\StandardCimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM MSFT_NetAdapter where ConnectorPresent=1")._NewEnum
while colItems[objItem]
{
   Name := objItem.Name
   Virtual := objItem.Virtual
   MsgBox % name
   MsgBox % virtual
}
I will continue searching.
thanks
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Virtual or Physical Network Adapter detection?

Post by malcev » 05 Feb 2023, 10:38

You need here instead of objItem.Description try to get guid property.

Code: Select all

objWMIService := ComObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
  colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
  while colItems[objItem]
  MsgBox % objItem.Description
After that run my code and also instead of objItem.Name get guid property.
If in my code guid is in guids from Your code then adapter is physical and ipenabled.

User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: Virtual or Physical Network Adapter detection?

Post by DataLife » 05 Feb 2023, 17:51

malcev wrote:
05 Feb 2023, 10:38
You need here instead of objItem.Description try to get guid property.

Code: Select all

objWMIService := ComObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
  colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
  while colItems[objItem]
  MsgBox % objItem.Description
After that run my code and also instead of objItem.Name get guid property.
If in my code guid is in guids from Your code then adapter is physical and ipenabled.
I could not find GUID on both, but I did find both can get the mac address. I am certain this will work.
MSFT_NetAdapter calls it "PermanentAddress"
Win32_NetworkAdapterConfiguration calls it "MACAddress"
I was able to confirm the mac address on my wireless card was present in both codes.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Virtual or Physical Network Adapter detection?

Post by malcev » 06 Feb 2023, 04:52

For me SettingID and InterfaceGuid are the same.

Post Reply

Return to “Ask for Help (v1)”