Hello,
What is the best way to know if the adapter changes state from disconncted
to enabled?

One way would be to do
while(1)
{
//query OID_GEN_MEDIA_CONNECT_STATUS
Sleep(2000); //or more often
}

but I don't like this method, is there a better way of letting windows
inform me when state is changed?

thanks
/Niklas

RE: adapter status by pavel_a

pavel_a
Tue Jul 05 10:35:03 CDT 2005

"Niklas" wrote:
> Hello,
> What is the best way to know if the adapter changes state from disconncted
> to enabled?

In user mode: WMI.
The sample below is vbscript. Same can be done in C++, .NET and so on.

In kernel mode, protocols just receive indications from their bound
miniports.

' ------------ cut here ----------------------------------
' ***** Receive media connect and disconnect events
Set objWMIServices=
GetObject("winmgmts:{impersonationLevel=impersonate}!root/wmi")
set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK1_")
set objSink2 = WScript.CreateObject("WbemScripting.SWbemSink","SINK2_")

objWMIServices.ExecNotificationQueryAsync objSink, "Select * from
MSNdis_StatusMediaConnect"
objWMIServices.ExecNotificationQueryAsync objSink2, "Select * from
MSNdis_StatusMediaDisconnect"

WScript.Echo "Waiting for Media_connect events..." & vbCrLf

While(1)
WScript.Sleep 1000
' or do something useful
Wend

'------- end main ------

Sub SINK1_OnObjectReady(wmiObject, wmiAsyncContext)
WScript.Echo "CONNECT event:" & vbCrLf & wmiObject.GetObjectText_()
End Sub

Sub SINK2_OnObjectReady(wmiObject, wmiAsyncContext)
WScript.Echo "DISCONNECT event:" & vbCrLf & wmiObject.GetObjectText_()
End Sub

' '-------------- cut here -----------

The above vbscript is a modified sample by Calvin Guan (thanks :)

--PA



Re: adapter status by Arkady

Arkady
Wed Jul 06 02:11:13 CDT 2005

Additionally : look at http://www.ndis.com/faq/QA01050301/default.htm
Arkady

"Pavel A." <pavel_a@NOwritemeNO.com> wrote in message
news:54736230-D8F1-415D-9D52-D66F637EF32C@microsoft.com...
> "Niklas" wrote:
>> Hello,
>> What is the best way to know if the adapter changes state from
>> disconncted
>> to enabled?
>
> In user mode: WMI.
> The sample below is vbscript. Same can be done in C++, .NET and so on.
>
> In kernel mode, protocols just receive indications from their bound
> miniports.
>
> ' ------------ cut here ----------------------------------
> ' ***** Receive media connect and disconnect events
> Set objWMIServices=
> GetObject("winmgmts:{impersonationLevel=impersonate}!root/wmi")
> set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK1_")
> set objSink2 = WScript.CreateObject("WbemScripting.SWbemSink","SINK2_")
>
> objWMIServices.ExecNotificationQueryAsync objSink, "Select * from
> MSNdis_StatusMediaConnect"
> objWMIServices.ExecNotificationQueryAsync objSink2, "Select * from
> MSNdis_StatusMediaDisconnect"
>
> WScript.Echo "Waiting for Media_connect events..." & vbCrLf
>
> While(1)
> WScript.Sleep 1000
> ' or do something useful
> Wend
>
> '------- end main ------
>
> Sub SINK1_OnObjectReady(wmiObject, wmiAsyncContext)
> WScript.Echo "CONNECT event:" & vbCrLf & wmiObject.GetObjectText_()
> End Sub
>
> Sub SINK2_OnObjectReady(wmiObject, wmiAsyncContext)
> WScript.Echo "DISCONNECT event:" & vbCrLf & wmiObject.GetObjectText_()
> End Sub
>
> ' '-------------- cut here -----------
>
> The above vbscript is a modified sample by Calvin Guan (thanks :)
>
> --PA
>
>