โดย chakrit » 21/07/2022 6:02 pm
อัพเดท
ตอนนี้สามารถทำให้ Restart เองได้แล้วโดยหากมีการเชื่อมต่อ
เพิ่มตัว UI

- ถาม - ตอบ คอมพิวเตอร์-2.png (17.52 KiB) Viewed 876 times
แต่ต้องไปตั้งค่าโดยถ้าหากมีการ Reset คอมพิวเตอร์แล้วให้ทำการ run ไฟล์สคริปต์ตัวนี้ขึ้นมา
เปิด CMD > shell:startup > นำไฟล์ไปใส่
เมื่อมีการ Restart ไฟล์สคริปต์ตัวนี้ก็จะถูกเรียกใช้งานหากอินเตอร์เน็ตหลุด ก็จะทำการ Restart
โค้ด: เลือกทั้งหมด
#SingleInstance, Force
TTW := 100 ;Time to wait in seconds
SetTimer, CheckInternetConnection, 5000 ; Check internet in 5 second intervals
Gui, Add, Text,, Amount of time (in seconds) to wait to restart:
Gui, Add, Checkbox, checked vQueryRestartCheckbox , AutoRestart on time-out
Gui, Add, Edit, w50 ys number vTTW gUpdateTTW, %TTW%
Gui, +AlwaysOnTop +ToolWindow
Gui, Show, y+100
return
UpdateTTW:
Gui, Submit, Nohide
return
CheckInternetConnection:
FileDelete, %A_Temp%\PingResult.txt
RunWait, cmd /c ping google.com -n 1 >%A_Temp%\PingResult.txt,, hide ; Google is a reliable site, so I chose that
FileRead, PingResult, %A_Temp%\PingResult.txt
IfInString, PingResult, Reply from
{
; ########### THIS CODE WILL BE RUN IF YOU HAVE AN INTERNET CONNECTION ########################
If (ProgressStatus)
{
Progress, off
ProgressStatus := 0
}
}
Else
{
; ########### THIS CODE WILL BE RUN IF YOU DO NOT HAVE AN INTERNET CONNECTION ########################
TrayTip, Connection Status:, Internet connection not established
ProgressStatus += 5 ; add 5 seconds to progress
If ((ProgressStatus/TTW)*100 >= 100)
{
Progress, % (ProgressStatus/TTW)*100, % Round((ProgressStatus/TTW)*100) "%"
Sleep, 1000 ; let the user see the status update
Progress, Off
ProgressStatus := 0
gosub, QueryRestart
}
else
Progress, % (ProgressStatus/TTW)*100, % Round((ProgressStatus/TTW)*100) "%", Internet connection interruption progress: ; Simple math to calculate status bar percent
}
return
QueryRestart: ; Destroy the GUIs, and do what needs to be done on progress bar completion
Gui, Submit, Nohide
SetTimer, CheckInternetConnection, Off
Gui, Destroy
If QueryRestartCheckbox
Shutdown, 6 ; Force reboot
else
Reload ; Reload script
return
สามารถโค้ดนี้ไปใช้ได้เลยคับ
โค้ดตัวนี้จะเป็นการเช็ค Ping ของ google.com หากไม่สามารถเช็ค Ping ได้หรือก็คือเน็ตหลุด จะทำการ เช็คหากเช็คแล้วไม่สามารถเชื่อมต่อได้ แบบในภาพจนถึง 100% ก็จะทำการ restart เครื่องคอมพิวเตอร์
อัพเดท
ตอนนี้สามารถทำให้ Restart เองได้แล้วโดยหากมีการเชื่อมต่อ
เพิ่มตัว UI
[attachment=0]ถาม - ตอบ คอมพิวเตอร์-2.png[/attachment]
แต่ต้องไปตั้งค่าโดยถ้าหากมีการ Reset คอมพิวเตอร์แล้วให้ทำการ run ไฟล์สคริปต์ตัวนี้ขึ้นมา
[b]เปิด CMD > shell:startup > นำไฟล์ไปใส่[/b]
เมื่อมีการ Restart ไฟล์สคริปต์ตัวนี้ก็จะถูกเรียกใช้งานหากอินเตอร์เน็ตหลุด ก็จะทำการ Restart
[code]
#SingleInstance, Force
TTW := 100 ;Time to wait in seconds
SetTimer, CheckInternetConnection, 5000 ; Check internet in 5 second intervals
Gui, Add, Text,, Amount of time (in seconds) to wait to restart:
Gui, Add, Checkbox, checked vQueryRestartCheckbox , AutoRestart on time-out
Gui, Add, Edit, w50 ys number vTTW gUpdateTTW, %TTW%
Gui, +AlwaysOnTop +ToolWindow
Gui, Show, y+100
return
UpdateTTW:
Gui, Submit, Nohide
return
CheckInternetConnection:
FileDelete, %A_Temp%\PingResult.txt
RunWait, cmd /c ping google.com -n 1 >%A_Temp%\PingResult.txt,, hide ; Google is a reliable site, so I chose that
FileRead, PingResult, %A_Temp%\PingResult.txt
IfInString, PingResult, Reply from
{
; ########### THIS CODE WILL BE RUN IF YOU HAVE AN INTERNET CONNECTION ########################
If (ProgressStatus)
{
Progress, off
ProgressStatus := 0
}
}
Else
{
; ########### THIS CODE WILL BE RUN IF YOU DO NOT HAVE AN INTERNET CONNECTION ########################
TrayTip, Connection Status:, Internet connection not established
ProgressStatus += 5 ; add 5 seconds to progress
If ((ProgressStatus/TTW)*100 >= 100)
{
Progress, % (ProgressStatus/TTW)*100, % Round((ProgressStatus/TTW)*100) "%"
Sleep, 1000 ; let the user see the status update
Progress, Off
ProgressStatus := 0
gosub, QueryRestart
}
else
Progress, % (ProgressStatus/TTW)*100, % Round((ProgressStatus/TTW)*100) "%", Internet connection interruption progress: ; Simple math to calculate status bar percent
}
return
QueryRestart: ; Destroy the GUIs, and do what needs to be done on progress bar completion
Gui, Submit, Nohide
SetTimer, CheckInternetConnection, Off
Gui, Destroy
If QueryRestartCheckbox
Shutdown, 6 ; Force reboot
else
Reload ; Reload script
return[/code]
สามารถโค้ดนี้ไปใช้ได้เลยคับ
โค้ดตัวนี้จะเป็นการเช็ค Ping ของ google.com หากไม่สามารถเช็ค Ping ได้หรือก็คือเน็ตหลุด จะทำการ เช็คหากเช็คแล้วไม่สามารถเชื่อมต่อได้ แบบในภาพจนถึง 100% ก็จะทำการ restart เครื่องคอมพิวเตอร์