John117 Posted April 17, 2009 Share Posted April 17, 2009 (edited) Hey guys, I am looking for a quick way to check internet status using no bandwidth and little cpu. Vista currently provides info which reads 'Access: Local and Internet" Is there a method of getting my yes or no from that source quickly? Thanks! Edited April 18, 2009 by Hatcheda Link to comment Share on other sites More sharing options...
Yashied Posted April 17, 2009 Share Posted April 17, 2009 (edited) Hey guys, I am looking for a quick way to check internet status using no bandwidth and little cpu. Vista currently provides info which reads 'Access: Local and Internet" Is there a method of getting my yes or no from that source quickly? Thanks!; #FUNCTION# ============================================================================================================== ; Function Name: _IsInternet ; Description: Check for Internet connection. ; Syntax: _IsInternet ( ) ; Parameter(s): None. ; Return Value(s): Success: Returns 1. ; Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ; are specific to the WinINet functions. ; ; Author(s): Yashied ; Note(s): - ;========================================================================================================================== func _IsInternet() local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) if (@error) then return SetError(1, 0, 0) endif local $wError = _WinAPI_GetLastError() return SetError((not ($wError = 0)), $wError, $Ret[0]) endfunc; _IsInternet Edited April 17, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
John117 Posted April 18, 2009 Author Share Posted April 18, 2009 (edited) expandcollapse popup; #FUNCTION# ============================================================================================================== ; Function Name: _IsInternet ; Description: Check for Internet connection. ; Syntax: _IsInternet ( ) ; Parameter(s): None. ; Return Value(s): Success: Returns 1. ; Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ; are specific to the WinINet functions. ; ; Author(s): Yashied ; Note(s): - ;========================================================================================================================== func _IsInternet() local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) if (@error) then return SetError(1, 0, 0) endif local $wError = _WinAPI_GetLastError() return SetError((not ($wError = 0)), $wError, $Ret[0]) endfunc; _IsInternetoÝ÷ Ûú®¢×£ ÷N§Â0jÉ÷ö×±¥ç-x,¢g)à²Ú²Ö§u×j)^tù^jǬyæÞ0«H«Þ¶¸vÚ¢Ú-zËbµ©ÝëfzIèÂ0"¶µ¢½«Þ¶¸uæö«¦åy©Ý¢yrëtßÛ0éȺÇí7ë+®ÈÁ«!¢bhël¢g)à)iÊ'²Ö§·[§¶)H¶êç¡÷æË«zW¬²Ø^Ólº{bn®xm§$¢{azx·]ý±¨tájy,²®r÷jëh×6#Region ;Includes #include <Date.au3> #EndRegion HotKeySet("{ESC}", "TerminateApp") While 1 Sleep(1000) _IsInternet() WEnd ; #FUNCTION# ============================================================================================================== ; Function Name: _IsInternet ; Description: Check for Internet connection. ; Syntax: _IsInternet ( ) ; Parameter(s): None. ; Return Value(s): Success: Returns 1. ; Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ; are specific to the WinINet functions. ; ; Author(s): Yashied ; Note(s): - ;========================================================================================================================== func _IsInternet() local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) if (@error) then return SetError(1, 0, 0) endif local $wError = _WinAPI_GetLastError() return SetError((not ($wError = 0)), $wError, $Ret[0]) ToolTip($Ret & " " & _NowCalc(), 0, 0) endfunc; _IsInternet Func TerminateApp() Exit 0 EndFunc ;==>TerminateApp Edited April 18, 2009 by Hatcheda Link to comment Share on other sites More sharing options...
Authenticity Posted April 18, 2009 Share Posted April 18, 2009 You don't need to get the last error. It returns true if connected, false otherwise. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 18, 2009 Share Posted April 18, 2009 In addition to Authenticity's post; $Rtn is an array. The only element you are interested in is $Rtn[0] Unless for debug purposes there is no need to return the error using the WinAPI udf. That file icludes far too much code to use it for reurning an error that you don't care about anyway. And to close out. Your tool tip will never get called. Once you return from a function, that's it, no more lines in the function are read. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
John117 Posted April 18, 2009 Author Share Posted April 18, 2009 (edited) ok, got it! #Region ;Includes #include <Date.au3> #EndRegion HotKeySet("{ESC}", "TerminateApp") While 1 Sleep(1000) _IsInternet() WEnd ; #FUNCTION# ============================================================================================================== ; Function Name: _IsInternet ; Description: Check for Internet connection. ; Syntax: _IsInternet ( ) ; Parameter(s): None. ; Return Value(s): Success: Returns 1. ; Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ; are specific to the WinINet functions. ; ; Author(s): Yashied ; Note(s): - ;========================================================================================================================== func _IsInternet() local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) ToolTip($Ret[0] & " " & _NowCalc(), 0, 0) if (@error) then return SetError(1, 0, 0) endif endfunc; _IsInternet Func TerminateApp() Exit 0 EndFunc ;==>TerminateApp Edit: Is this clean? could it cause any problems as is? Could I run in to errors? very important that it doesnt mess up my script . . . Edited April 18, 2009 by Hatcheda Link to comment Share on other sites More sharing options...
GEOSoft Posted April 18, 2009 Share Posted April 18, 2009 func _IsInternet() local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) ToolTip($Ret[0] & " " & _NowCalc(), 0, 0) Return $Ret[0];; In case you want to do something with the return value endfunc; _IsInternet Func TerminateApp() Exit 0 EndFunc ;==>TerminateApp George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
John117 Posted April 18, 2009 Author Share Posted April 18, 2009 Tanks! Link to comment Share on other sites More sharing options...
martin Posted April 18, 2009 Share Posted April 18, 2009 Tanks!You might not have solved your problem with the function InternetGetConnectedState because, despite its name, it doesn't check that there is a connection to the internet. You need to use ping. This post answered a very similar question. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
John117 Posted April 18, 2009 Author Share Posted April 18, 2009 You might not have solved your problem with the function InternetGetConnectedState because, despite its name, it doesn't check that there is a connection to the internet. You need to use ping. This post answered a very similar question.Martin, thanks for the reply! - Testing out your download now. frequent calls and slowing will be a prob otherwise. -it will be called about 100 times a sec . . . . depending on how fast I can keep my loop . . . . Link to comment Share on other sites More sharing options...
John117 Posted April 18, 2009 Author Share Posted April 18, 2009 You might not have solved your problem with the function InternetGetConnectedState because, despite its name, it doesn't check that there is a connection to the internet. You need to use ping. This post answered a very similar question.Come to think about it . . . how much will google like me if I ping them 52 million times this year :-Pwas mostly needing to check if my wireless dropped anyway. I never loose internet. just connection to my wireless. :-) Thanks though . . . Link to comment Share on other sites More sharing options...
GEOSoft Posted April 18, 2009 Share Posted April 18, 2009 (edited) func _IsInternet() Local $iConnected = 1 local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) If $Ret[0] Then Return SetError(0) Else ;; By moving the tooltip here it only displays if there is a problem ToolTip("No Internet Connection " & _NowCalc(), 0, 0, "Internet Status", 2, 5) Return SetError(1) EndIf endfunc; _IsInternet Edited for stupidity. Obviously if $Ret[0] = 0 Then You can't ping anything anyway. Edited April 18, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now