Hello,
i'm having trouble writing code that will do the following:
infinite loop. Every 1 minute check if the computer is online (try to ping a server or something), if the machine is online, do nothing, else try again in a minute (do nothing basically), but if machine is offline for 5 minutes then shut it down.
What is going on is, I bought a UPS, that doesn't have a USB port, so the UPS can't shutdown my PC. So figured, if my connection is down then there is a 99% chance that my electricity isn't working either (my ISP is great).
been digging the forum and can't figure it out by myself
Can anybody help me? Buying virtual beer
Check if connection to server and do something Topic is solved
Re: Check if connection to server and do something
Would you mind to specify that UPS (brand/type/..)?
Re: Check if connection to server and do something
Why not getting a USB Port card ?
Skan has provided the code for checking inernetconnection , tried it on win10 .The code is basic you need to adapt it to your needs
Skan has provided the code for checking inernetconnection , tried it on win10 .The code is basic you need to adapt it to your needs
Code: Select all
#persistent
SetTimer, check_connection, 300000 ; 5min = 5*60*1000 ms
return
check_connection:
If ConnectedToInternet()
return
else
{
Msgbox, 4, WinInet.dll, OFFLINE! Shutdown? , 20 ;timeout 20 sec
IfMsgBox, yes
Shutdown, Code
else
exitapp ; to prevent repeating shutdown attemps
}
Return
; code from Skan https://autohotkey.com/board/topic/80587-how-to-find-internet-connection-status/
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}
Re: Check if connection to server and do something
My UPS is Tecnoware UPS ERA Plus 750. how could I install a USB card? thanks for the code, wil try it later, when i get home from work.
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Check if connection to server and do something
InternetGetConnectedState doesn't actually check for connection, but validity of the connection state (LAN). For your case, this should work, considering if your router/AP has no power, there will be no LAN. To reliably check if you are connected to the internet, however, you should use Ping a server, either in the console (see comspec), or you can use InternetCheckConnection.
Re: Check if connection to server and do something
What do you mean with reliably? is the InternetGetConnectedState unreliable or did you mean something else?
Re: Check if connection to server and do something
Masonjar13 has a valid point.But if your router is not powered through the UPS the check is enough.I would use this instead of pinging for just looking if power is off.
Actually i would install a USB hub or card ,it is only a few euros on amazon
Re: Check if connection to server and do something
Thanks for the reply. you misunderstood me, the UPS doesn't have a USB interface, so I can't connect it to my PC (which is basicaly my home server running 24/7), that is powered by the UPS. Thats why I need the program to shutdown my pc
Re: Check if connection to server and do something
I don't get the idea why that UPS keeps the box alive but won't allow triggering it for a managed shutdown
Re: Check if connection to server and do something
My bad MyGiG for not reading your post properly.I am so used to have UPS with usb that i assumed it was the PC lacking a spare one
Greetings
Greetings
Re: Check if connection to server and do something
Yeah, I didn't even know, they come without a USB interface :/ learned the hard way. Anyway thank you all for the replys!
Who is online
Users browsing this forum: Google [Bot], imstupidpleshelp, jaka1 and 176 guests