Skip to content

Instantly share code, notes, and snippets.

@NateScarlet
Last active August 22, 2016 07:55
Show Gist options
  • Save NateScarlet/4e53f69d88475772490b07a5e826fb1a to your computer and use it in GitHub Desktop.
Save NateScarlet/4e53f69d88475772490b07a5e826fb1a to your computer and use it in GitHub Desktop.
托盘显示网络连通性
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;~ if not A_IsAdmin ;确保管理员权限
;~ {
;~ Run *RunAs "%A_ScriptFullPath%" ; 需要 v1.0.92.01+
;~ ExitApp
;~ }
CoordMode, Mouse, Client
ahkcs := "http://www.steampowerd.com"
Menu, Tray, Icon, imageres.dll, 21
Loop
{
NetStatus := % W_InternetCheckConnection(ahkcs) ? "网络正常": "网络中断"
If (NetStatus != LastNetStatus)
{
TrayTip, , %NetStatus%
LastNetStatus := NetStatus
}
If (NetStatus = "网络正常")
Menu, Tray, Icon, imageres.dll, 21
If (NetStatus != "网络正常")
Menu, Tray, Icon, imageres.dll, 85
Sleep, 1000
}
; 判断是否可以与某个 URL 建立连接
W_InternetCheckConnection(lpszUrl)
{
FLAG_ICC_FORCE_CONNECTION := 0x1
dwReserved := 0x0
return, DllCall("Wininet.dll\InternetCheckConnection", "Ptr", &lpszUrl, "UInt", FLAG_ICC_FORCE_CONNECTION, "UInt", dwReserved, "Int")
}
@NateScarlet
Copy link
Author

运行后会在托盘有一个代表能否连接至steam的图标
如果需要测试其他网站可以在第14行修改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment