Makave2345 Posted March 27, 2011 Posted March 27, 2011 (edited) The below code I found here, works great for me. The only thing that I would like to change is that when a connection is not found.. As it is now, if a connection is not found, it will say "Not connected" pause, and then continue on through the rest of my script.. What I would like to have it do, is if a connection is not found, say "Not connected", pause, then exit without continuing through the rest of my script. When a connection is found, It works like I would want... But I dont want if to continue the rest of the script if one is not found. Hope thats clear enough.. Thanks for any help you can give me on this matter. $INTERNET_CONNECTION_MODEM = 0x1 $INTERNET_CONNECTION_LAN = 0x2 $INTERNET_CONNECTION_PROXY = 0x4 $INTERNET_CONNECTION_MODEM_BUSY = 0x8 $INTERNET_RAS_INSTALLED = 0x10 $INTERNET_CONNECTION_OFFLINE = 0x20 $INTERNET_CONNECTION_CONFIGURED = 0x40 $ret = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0) If $ret[0] then ;check type of connection $sX = "Internet connection found!" If BitAND($ret[1], $INTERNET_CONNECTION_MODEM) Then $sX = $sX & "MODEM" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_LAN) Then $sX = $sX & "LAN" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_PROXY) Then $sX = $sX & "PROXY" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX = $sX & "MODEM_BUSY" & @LF If BitAND($ret[1], $INTERNET_RAS_INSTALLED) Then $sX = $sX & "RAS_INSTALLED" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE) Then $sX = $sX & "OFFLINE" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX = $sX & "CONFIGURED" & @LF Else $sX = "Not Connected" Endif MsgBox(4096,$ret[0] & ":" & $ret[1],$sX,10) Edited March 27, 2011 by Makave2345
Makave2345 Posted March 27, 2011 Author Posted March 27, 2011 Or a even more ideal solution if anybody could help me merge them... Would be if a connection is found run this and then continue on with the rest of the script. #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $started = 1 $mainwindow = GUICreate("Internet Connection Results!", 310, 100) GUICtrlCreateLabel("Internet Connection Found!", 83, 15) $btnExit = GUICtrlCreateButton("Continue", 120, 50, 65) GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate") GUICtrlSetOnEvent($btnExit, "_Terminate") GUISetState(@SW_SHOW) While 1 for $i = 6 to 1 Step -1 GUICtrlSetData($btnExit,"Continue (" & $i & ")") sleep(1000) Next If $started Then GUIDelete($mainwindow) EndIf Exit WEnd Func _Terminate() $started = 0 Exit EndFunc ;==>_Terminate If its not found, run this then exit... #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $started = 1 $mainwindow = GUICreate("Internet Connection Results!", 310, 100) GUICtrlCreateLabel("Internet Connection Not Found!", 80, 15) $btnExit = GUICtrlCreateButton("Exit", 120, 50, 65) GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate") GUICtrlSetOnEvent($btnExit, "_Terminate") GUISetState(@SW_SHOW) While 1 for $i = 6 to 1 Step -1 GUICtrlSetData($btnExit,"Exit (" & $i & ")") sleep(1000) Next If $started Then GUIDelete($mainwindow) EndIf Exit WEnd Func _Terminate() $started = 0 Exit EndFunc ;==>_Terminate
enaiman Posted March 27, 2011 Posted March 27, 2011 Well, welcome to the forum ... I know that everybody has to start from scratch at some point but not putting any effort into learning, you'll get nowhere. First - you were bumping your post in 40 minutes time which is not allowed around here - please give it a day or so next time. Second: I will quote you: What I would like to have it do, is if a connection is not found, say "Not connected", pause, then exitLet's break this into smaller bits: - say "Not Connected" How would you accomplish that? MsgBox maybe? - pause Sleep? - exit This one is more than obvious because the command is .... Exit I am all about helping people to learn but when I see laziness that drives me nuts. So, considering what I have specified above, the result would be: $INTERNET_CONNECTION_MODEM = 0x1 $INTERNET_CONNECTION_LAN = 0x2 $INTERNET_CONNECTION_PROXY = 0x4 $INTERNET_CONNECTION_MODEM_BUSY = 0x8 $INTERNET_RAS_INSTALLED = 0x10 $INTERNET_CONNECTION_OFFLINE = 0x20 $INTERNET_CONNECTION_CONFIGURED = 0x40 $ret = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0) If $ret[0] then ;check type of connection $sX = "Internet connection found!" If BitAND($ret[1], $INTERNET_CONNECTION_MODEM) Then $sX = $sX & "MODEM" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_LAN) Then $sX = $sX & "LAN" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_PROXY) Then $sX = $sX & "PROXY" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX = $sX & "MODEM_BUSY" & @LF If BitAND($ret[1], $INTERNET_RAS_INSTALLED) Then $sX = $sX & "RAS_INSTALLED" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE) Then $sX = $sX & "OFFLINE" & @LF If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX = $sX & "CONFIGURED" & @LF MsgBox(0, "Result:", $sX) Else MsgBox(0, "Result:", "Not Connected") Sleep(2000) Exit Endif SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
Makave2345 Posted March 27, 2011 Author Posted March 27, 2011 Well thank you for the help... Although on your first point. I was NOT bumping my post. Simply had another idea and posted it... Wouldn't have done anygood to bump it since it was still at the top anyway.. As far a laziness goes, i have been working on this one particular thing for a while now... I already knew about the sleep and exit commands... It was the use of the double MsgBox like in your solution that was giving me fits... I do appreciate the help I just dont appreciate how you assume that you know that everyone else is taking the lazy way out....
enaiman Posted March 27, 2011 Posted March 27, 2011 I do appreciate the help I just dont appreciate how you assume that you know that everyone else is taking the lazy way out....I was only refering to you in this case, not everyone else. Anyway - how could I not think about laziness when the very first AutoIt example is about a messagebox? Message Box is one of the top 10 most used commands and helps alot with debugging, keep that in mind for the future. You have your solution - problem solved - good luck in your further coding. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
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