반응형

 

 

 

오토핫키 커뮤니티를 참고하다가 재미있는 소스가 있어서

글을 써보네요!

 

 

https://peuming.tistory.com/65

 

오토핫키(Autohotkey) v1 현재 인터넷,WIFI이 연결되어 있는지 확인

ConnectedToInternet() 함수 입니다.오토핫키 커뮤니티에서 가져왔습니다 . If not ConnectedToInternet(){ msgbox,64,안내,인터넷상태가 원활하지 않습니다. return}ConnectedToInternet(flag=0x40){Return DllCall("Wininet.dll\Inte

peuming.tistory.com

 

위 주소는, 인터넷 혹은 WIFI 가 연결되어 있는지

여부를 확인하는 소스코드입니다

 

 

 


 

 

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=113844

 

Alert on internet connect or disconnect - AutoHotkey Community

Post your working scripts, libraries and tools for AHK v1.1 and older malcev Posts: 1769 Joined: 12 Aug 2014, 12:37 @ Quote 12 Feb 2023, 23:01 https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mpc/network-awareness-on-windows-vista-and-wi

www.autohotkey.com

 

원문 주소입니다

 

https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mpc/network-awareness-on-windows-vista-and-windows-7

 

Network Awareness in Windows Vista and Windows 7

How to create network-aware applications that run on Windows \ 160;Vista and Windows \ 160;7.Note  To download the complete code samples discussed in this topic, see Microsoft Windows Network List Manager (NLM) Samples in Code Gallery. .

learn.microsoft.com

 

 

하단에 적혀있는 스크립트는,

INetWorkListManagerEvents를 포착하여 인터넷 연결해제 / 연결시 이벤트를 발생시키는 구조입니다.

 

 

#Persistent
OnExit, ExitSub
NetworkListManager := ComObjCreate(CLSID_NetworkListManager := "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
if (NetworkListManager.GetConnectivity & 0x40) or (NetworkListManager.GetConnectivity & 0x400)   ; NLM_CONNECTIVITY_IPV4_INTERNET or NLM_CONNECTIVITY_IPV6_INTERNET
{
   InternetExist := 1
   msgbox internet ok
}
else
{
   InternetExist := 0
   msgbox no internet
}
Events := [3 ;QueryInterface
          ,1 ;AddRef
          ,1 ;Release
          ,2] ;ConnectivityChanged
VarSetCapacity(CallbackTable, A_PtrSize*Events.MaxIndex(), 0)
For Index, ParameterCount In Events
   NumPut(RegisterCallback("EventHandler", "Fast", ParameterCount, A_Index-1), CallbackTable, A_PtrSize*(A_Index-1))
pSink := DllCall("GlobalAlloc", "uint", 0, "ptr", A_PtrSize+4, "ptr")
NumPut(&CallbackTable, pSink+0, 0)
NumPut(InternetExist, pSink+0, A_PtrSize, "uint")
ConnectionPointContainer := ComObjQuery(NetworkListManager, IID_IConnectionPointContainer := "{B196B284-BAB4-101A-B69C-00AA00341D07}")
VarSetCapacity(CLSID, 16, 0)
DllCall("ole32\CLSIDFromString", "wstr", IID_INetworkListManagerEvents := "{DCB00001-570F-4A9B-8D69-199FDBA5723B}", "ptr", &CLSID)
DllCall(NumGet(NumGet(ConnectionPointContainer + 0) + A_PtrSize*4), "ptr", ConnectionPointContainer, "ptr", &CLSID, "ptr*", ConnectionPoint)   ; IConnectionPointContainer::FindConnectionPoint
ObjRelease(ConnectionPointContainer)
DllCall(NumGet(NumGet(ConnectionPoint + 0) + A_PtrSize*5), "ptr", ConnectionPoint, "ptr", psink, "uint*", nCookie)   ; IConnectionPoint::Advise
return



EventHandler(this, guid = "", ppvObject = "")
{
   static IID_IUnknown, p1, p2, refCount := 1, InternetExist
   if !IID_IUnknown
   {
      VarSetCapacity(p1, 16, 0)
      DllCall("ole32\CLSIDFromString", "wstr", IID_IUnknown := "{00000000-0000-0000-C000-000000000046}", "ptr", &p1)
      VarSetCapacity(p2, 16, 0)
      DllCall("ole32\CLSIDFromString", "wstr", IID_INetworkListManagerEvents := "{DCB00001-570F-4A9B-8D69-199FDBA5723B}", "ptr", &p2)
      InternetExist := NumGet(this+0, A_PtrSize, "uint")
   }
   If (A_EventInfo = 0)
   {
      if DllCall("ole32\IsEqualGUID", "ptr", guid, "ptr", &p1) or DllCall("ole32\IsEqualGUID", "ptr", guid, "ptr", &p2)
      {
         NumPut(this, ppvObject+0)
         refCount++
         return 0
      }
      else
      {
         NumPut(0, ppvObject+0)
         return 0x80004002
      }
   }
   else if (A_EventInfo = 1)
   {
      refCount++
      return refCount
   }
   else if (A_EventInfo = 2)
   {
      if (refCount > 0)
      {
         refCount--
         if (refCount = 0)
            DllCall("GlobalFree", "ptr", this, "ptr")
      }
      return refCount
   }
   else if (A_EventInfo = 3)   ; ConnectivityChanged
   {
      if (guid & 0x40) or (guid & 0x400)   ; NLM_CONNECTIVITY_IPV4_INTERNET or NLM_CONNECTIVITY_IPV6_INTERNET
      {
         if !InternetExist
         {
            InternetExist := 1
            msgbox internet appears
         }
      }
      else
      {
         if InternetExist
         {
            InternetExist := 0
            msgbox internet disappears
         }
      }
      return 0
   }
}

ExitSub:
DllCall(NumGet(NumGet(ConnectionPoint + 0) + A_PtrSize*6), "ptr", ConnectionPoint, "uint", nCookie)   ; IConnectionPoint::Unadvise
ObjRelease(ConnectionPoint)
ObjRelease(pSink)
ExitApp

 

 

 

반응형

+ Recent posts