Auto Reboot for Windows XP/7/10

Auto Reboot Application

Last night I just know if make task scheduler on Windows XP is just different matter from Windows 7 or Windows 10. On other Windows (7/10) it just create simple task scheduler for reboot/shutdown computer at certain time. So I decided to create little application under VB6 to do the task reboot in force mode (every morning at 5 AM) of my Windows XP pc that I use for RF-LINK RoIP.

If you want to use this application, just create shorcut and put in Startup Folder, so the application will run automatically when Windows starting up. Download here.

Here is my tiny code (tested on Windows XP/7/10):

Option Explicit
 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
 Private Declare Function OpenIcon Lib "user32" (ByVal hWnd As Long) As Long
 Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
 Const GW_HWNDPREV = 3

 Private Sub Command1_Click()
     Form1.WindowState = 1
 End Sub

 Private Sub Command2_Click()
     Keluar
 End Sub

 Private Sub Command3_Click()
     Dim answer
     answer = MsgBox("Are you sure you want to reboot now?", vbCritical + vbYesNo, "Warning")
     If answer = vbYes Then
         RestartWindows
     End If
 End Sub

 Private Sub Form_Load()
     If App.PrevInstance Then SHOWPREVINSTANCE
 End Sub

 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
     If UnloadMode = vbFormControlMenu Then Cancel = True
 End Sub

 Private Sub Form_Unload(Cancel As Integer)
     Set Form1 = Nothing
 End Sub

 Private Sub Timer1_Timer()
     Label1.Caption = Format(Now, "dd-mm-yyyy HH:mm:ss")
     'Label1.Caption = Format(Time, "hh:mm:ss")
     If Format(Time, "HH:mm:ss") = "05:00:00" Then
         RestartWindows
     End If
 End Sub

 Private Sub Keluar()
     Dim answer
     answer = MsgBox("Are you sure you want to exit?", vbCritical + vbYesNo, "Warning")
     If answer = vbYes Then
         Unload Me
     End If
 End Sub

 Private Sub SHOWPREVINSTANCE()
     Dim OldTitle As String
     Dim ll_WindowHandle As Long
     OldTitle = App.Title
     App.Title = "Aplikasi ini akan ditutup!"
     ll_WindowHandle = FindWindow("ThunderRT6Main", OldTitle)
     If ll_WindowHandle = 0 Then Exit Sub
     ll_WindowHandle = GetWindow(ll_WindowHandle, GW_HWNDPREV)
     Call OpenIcon(ll_WindowHandle)
     Call SetForegroundWindow(ll_WindowHandle)
     End
 End Sub

 Private Sub RestartWindows()
     If Dir("C:\WINDOWS\RUNDLL.EXE") <> "" Then
         Shell "C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows"
     Else
         Shell "SHUTDOWN -r -f -t 01"
     End If
 End Sub
Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.