Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, hi all,
is there a way, knowing an network interface name, to "block" it, I mean stop it from receiving/sending bits, or if not, to disable it?
I try with
#compile __CPerformanceCounter
CPerformanceCounter c
Thanks.
Posts: 12,041
Threads: 140
Joined: Dec 2002
Posts: 795
Threads: 136
Joined: Feb 2009
Posts: 795
Threads: 136
Joined: Feb 2009
is Win32_NetworkAdapter class available through QM natively?
Posts: 12,041
Threads: 140
Joined: Dec 2002
Macro WMI - network connections - list, disable, enable
;note: run as administrator.
out
def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)
IDispatch x
foreach x col
,;out x.NetConnectionId
,str name=x.Name
,out name
,if name="Realtek PCIe GBE Family Controller"
,,x.Disable
,,mes "Now should be disabled. Click OK to enable again."
,,x.Enable
,,;break
Posts: 795
Threads: 136
Joined: Feb 2009
was playing with this, that enumerates network interfaces
typelib WbemScripting {565783C6-CB41-11D1-8B02-00600806D9B6} 1.1
WbemScripting.SWbemServices objWMIService._getfile("winmgmts:")
WbemScripting.SWbemObjectSet colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL ","WQL",WbemScripting.wbemFlagReturnImmediately|WbemScripting.wbemFlagForwardOnly,0)
;"SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL"
WbemScripting.SWbemObject objProcess
foreach objProcess colProcesses
,out objProcess.Properties_.Item("Name" 0).Value
will try yours instead...
Posts: 795
Threads: 136
Joined: Feb 2009
Tweaked, runned, Perfect, wow you're the man!!!!
Posts: 795
Threads: 136
Joined: Feb 2009
to carry on implementation on my own (if i can), where can i find IDispatch x reference for x members availability?
I search to test status, and x.Status does not seem to exist...
Posts: 12,041
Threads: 140
Joined: Dec 2002
Posts: 795
Threads: 136
Joined: Feb 2009
Should have guessed, you just answered my first question...great
Maybe integrated in next QM version
Posts: 795
Threads: 136
Joined: Feb 2009
BUT:
str name=x.NetConnectionID
gives
Error (RT) in <open ":3264: /324">Stoppe_VPN: unknown member
and it's the item right after Name...
Why?
Posts: 12,041
Threads: 140
Joined: Dec 2002
In my first example was "SELECT Name ...". If want more members, use "SELECT * ...".
Posts: 12,041
Threads: 140
Joined: Dec 2002
This also works.
Macro Network connections - disable, enable
;note: run as administrator.
if(RunConsole2("netsh interface set interface ''Ethernet 3'' admin=disable")) end "failed"
mes "Now should be disabled. Click OK to enable again."
if(RunConsole2("netsh interface set interface ''Ethernet 3'' admin=enable")) end "failed"
Posts: 795
Threads: 136
Joined: Feb 2009
damned, i missed it...thanks
Posts: 795
Threads: 136
Joined: Feb 2009
Posts: 12,041
Threads: 140
Joined: Dec 2002
Posts: 795
Threads: 136
Joined: Feb 2009
**From MSDN
NetConnectionStatus
Data type: uint16
Access type: Read-only
word i=x.NetConnectionStatus
Error (RT) type mismatch <help #IDP_ERR>?
Posts: 12,041
Threads: 140
Joined: Dec 2002
Possibly its type is VT_NULL (1). It means empty, and error if trying to convert to some other type.
VARIANT v=x.NetConnectionStatus
out v.vt
On my PC NetConnectionStatus gives word 2 or 7. But Status is VT_NULL.
Posts: 795
Threads: 136
Joined: Feb 2009
Posts: 795
Threads: 136
Joined: Feb 2009
last one (for the moment)
Is a function created at QM launch and constantly monitoring an network interface for some properties is "heavy" for the system,
or is it better to have a toolbar with a procedure attached more efficient??? and for the latter, what is the message to wait for (something like WM_ADAPTERSTATUSCHANGED)?
Because I already have one toolbar used for monitoring some windows events already running...but don't want to overload it...
Posts: 12,041
Threads: 140
Joined: Dec 2002
Function (thread) itself isn't heavy. Depends on what it does and how frequently.
Message - use OutWinMsg in a window/dialog/toolbarhook procedure to see received messages.
Posts: 795
Threads: 136
Joined: Feb 2009
ok, will do..
Thanks for all again
Posts: 795
Threads: 136
Joined: Feb 2009
i struggle with getting information, as i have many type mismatches when trying to retreive
parameter information, even if i give return variable the right type (uint16, string etc)
How to debug error to find the correct variable type to give for return?
class Win32_NetworkAdapter : CIM_NetworkAdapter
{
string AdapterType;
uint16 AdapterTypeID;
boolean AutoSense;
uint16 Availability;
string Caption;
uint32 ConfigManagerErrorCode;
boolean ConfigManagerUserConfig;
string CreationClassName;
string Description;
string DeviceID;
boolean ErrorCleared;
string ErrorDescription;
string GUID;
uint32 Index;
datetime InstallDate;
boolean Installed;
uint32 InterfaceIndex;
uint32 LastErrorCode;
string MACAddress;
string Manufacturer;
uint32 MaxNumberControlled;
uint64 MaxSpeed;
string Name;
string NetConnectionID;
uint16 NetConnectionStatus;
boolean NetEnabled;
string NetworkAddresses[];
string PermanentAddress;
boolean PhysicalAdapter;
string PNPDeviceID;
uint16 PowerManagementCapabilities[];
boolean PowerManagementSupported;
string ProductName;
string ServiceName;
uint64 Speed;
string Status;
uint16 StatusInfo;
string SystemCreationClassName;
string SystemName;
datetime TimeOfLastReset;
};
Posts: 795
Threads: 136
Joined: Feb 2009
foreach x col
str name=x.Name
out name
TAP-Windows Adapter V9
Microsoft Kernel Debug Network Adapter
Qualcomm Atheros AR8171/8175 PCI-E Gigabit Ethernet Controller (NDIS 6.30)
Carte réseau Broadcom 802.11ac
Broadcom NetXtreme Gigabit Ethernet
Microsoft Wi-Fi Direct Virtual Adapter
Bluetooth Device (RFCOMM Protocol TDI)
Bluetooth Device (Personal Area Network)
Microsoft Hosted Network Virtual Adapter
WAN Miniport (SSTP)
WAN Miniport (IKEv2)
WAN Miniport (L2TP)
WAN Miniport (PPTP)
WAN Miniport (PPPOE)
WAN Miniport (IP)
WAN Miniport (IPv6)
WAN Miniport (Network Monitor)
Realtek USB GbE Family Controller
foreach x col
str name=x.Name
out name
out x.NetConnectionId
Microsoft Kernel Debug Network Adapter
Error (RT) in <open ":168: /336">: 0x80020005, type mismatch
Posts: 12,041
Threads: 140
Joined: Dec 2002
Macro WMI - network connections - list, disable, enable
,VARIANT v=x.NetConnectionId
,out v.vt
Then look in QM help topic "VARIANT members table".
If some vt are 0 or 1, look in SELECT, it should be "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL". In my first example probably was without "WHERE NetConnectionId != NULL".
Posts: 795
Threads: 136
Joined: Feb 2009
lol, pretty cryptic, but I missed I must output VARIANT v.vt, not VARIANT v, learned that at least
Posts: 795
Threads: 136
Joined: Feb 2009
ok, i did get some improvements using VARIANT
Some fill correct datas
v=x.Name
out "Name: %S" v.pbstrVal
v=x.AdapterType
out "Type: %S" v.pbstrVal
v=x.AdapterTypeID
out "AdapterTypeID: %i" v.uintVal
v=x.Availability
out "Availability: %i" v.uintVal
some don't (like Status).
1. When v.vt = 1, means I can't access data from the variable (as x.Status)? any of variable type does generate type mismatch
2. Some are date (as x.TimeOfLastReset), using v.date is giving 00:00:00
ideas?
Posts: 795
Threads: 136
Joined: Feb 2009
How to deal with arrays?
one property is this
string NetworkAddresses[];
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE IPEnabled=''TRUE''" ,@,IFlags)
foreach x col
foreach v x.NetworkAddresses
out v.vt
does not work....
Posts: 12,041
Threads: 140
Joined: Dec 2002
On my PC it is VT_NULL. If it would not be null, assign it to an ARRAY(str) variable.
Macro Macro272
;note: run as administrator.
out
def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)
IDispatch x
foreach x col
,str name=x.Name
,out name
,VARIANT v=x.NetworkAddresses
,sel v.vt
,,case VT_ARRAY|VT_BSTR
,,ARRAY(str) a=x.NetworkAddresses
,,int i
,,for i 0 a.len
,,,out a[i]
,,
,,case VT_NULL
,,out "no data, sorry"
,,
,,case else
,,end "what?!"
,,
Posts: 795
Threads: 136
Joined: Feb 2009
TAP-Windows Adapter V9
no data, sorry
Qualcomm Atheros AR8171/8175 PCI-E Gigabit Ethernet Controller (NDIS 6.30)
no data, sorry
Carte réseau Broadcom 802.11ac
no data, sorry
Broadcom NetXtreme Gigabit Ethernet
no data, sorry
|