Hey =)
ich habe vor ein Shutdown Programm zu schreiben, das den Rechner nach einer bestimmten Zeit Herunterfährt, Neustartet oder in den Ruhezustand versetzt.
Mir ist bewusst, dass es dafür viele fertige Scripte oder sogar Programme zum downloaden gibt, aber ich bin erst vor kurzem auf Autoit gestoßen und würde gerne einen eigenen Versuch starten.
Das kleine Programm soll so aussehen:
GUI 1: Input für "Stunden", "Minuten" und "Sekunden" + Buttons für "Herunterfahren", "Neustarten", "Ruhezustand"
Nach Klick auf einen der Button wird der dazugehörige Befehl ausgeführt und GUI 2 wird geöffnet
GUI 2: Button für "Abbruch" und "OK und Schließen" (Evtl. noch ein Countdown wenn alles läuft, wie es soll)
Soviel zum Konzept.
Bei der Umsetzung bin ich meiner Meinung nach schon ein Stück vorran gekommen.
Probleme bereitet mir nun der Befehl:
Run(@comspec & " /c " & 'shutdown /f /s /t ' & $Timer,"", @SW_hide)
[/autoit]
Ich weiß, dass viele Wege nach Rom führen, wie z.B. Run(cmd.exe) oder _RunDOS() aber ich würde gerne das CMD Fenster verborgen lassen.
Mein Problem ist nun, dass bei obigem Befehl, nichts passiert, außer dass sich das Programm nochmal öffnet, Bzw. das GUI 1.
Wenn ich @SW_hide weglasse, sehe ich, wie sich das CMD Fenster öffnet, dass komplett leer ist.
Hier mein kompletter Code:
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#Region ### START Koda GUI section ### Form=z:\*****\autoit\shutdown\shutdown.kxf
$Form1 = GUICreate("Shutdown Timer", 369, 301, 216, 162)
$Label = GUICtrlCreateLabel("Stunden", 68, 64, 54, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Labe2 = GUICtrlCreateLabel("Minuten", 154, 64, 50, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Labe3 = GUICtrlCreateLabel("Computer in ...", 68, 16, 151, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Labe4 = GUICtrlCreateLabel("Sekunden", 234, 64, 66, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("0", 68, 38, 41, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("0", 154, 38, 41, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("1", 234, 38, 41, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Herunterfahren", 112, 114, 200, 50)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Neu starten", 112, 170, 200, 50)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("Ruhezustand", 112, 225, 200, 50)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Icon1 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Shutdown.ico", -0, 56, 114, 50, 50)
$Icon2 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Restart.ico", -0, 56, 170, 50, 50)
$Icon4 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Hibernate.ico", -0, 56, 226, 50, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
$Timer = GUICtrlRead($Input1)*3600 + GUICtrlRead($Input2)*60 + GUICtrlRead($Input3)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Run(@comspec & " /c " & 'shutdown /f /s /t ' & $Timer,"",@SW_hide) ; besser als _RunDos("shutdown -s -t " & $Timer) oder Run(cmd.exe)
GUIDelete($Form1)
gui2()
Case $Button2
Run(@comspec & " /c " & 'shutdown /f /r /t ' & $Timer,"",@SW_hide)
GUIDelete($Form1)
gui2()
Case $Button3
GUIDelete($Form1)
Run("cmd.exe")
Opt("WinTitleMatchMode", 2)
WinWaitActive("cmd", "", 10) ; besser als WinWaitActive("Administrator: C:\Windows\system32\cmd.exe", "", 10)
Send("C:")
Send("{ENTER}")
Send("ping -n " & $Timer & " 127.0.0.1 > NUL 2>&1 && shutdown /h /f")
Send("{ENTER}")
WinSetState("cmd.exe", "", @SW_MINIMIZE) ; besser als WinSetState("Administrator: C:\Windows\system32\cmd.exe", "", @SW_MINIMIZE)
gui3 ()
EndSwitch
WEnd
Func gui2 ()
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#Region ### START Koda GUI section ### Form=z:\*****\autoit\shutdown\countdown.kxf
$Form2 = GUICreate("Shutdown", 381, 194, 217, 167)
$Button2_1 = GUICtrlCreateButton("Abbruch!", 118, 43, 200, 50)
$Icon1 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Abort.ico", -0, 62, 43, 50, 50)
$Button2_2 = GUICtrlCreateButton("OK und Schließen", 118, 99, 200, 50)
$Icon2 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Approved.ico", -0, 62, 99, 50, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 2
$nMsg = GUIGetMsg (2)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2_2
Exit
Case $Button2_1
Run(@comspec & " /c " & 'shutdown /a',"",@SW_hide)
Exit
EndSwitch
WEnd
EndFunc
Func gui3 ()
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#Region ### START Koda GUI section ### Form=z:\*****\autoit\shutdown\countdown.kxf
$Form3 = GUICreate("Shutdown", 381, 194, 217, 167)
$Button3_1 = GUICtrlCreateButton("Abbruch!", 118, 43, 200, 50)
$Icon1 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Abort.ico", -0, 62, 43, 50, 50)
$Button3_2 = GUICtrlCreateButton("OK und Schließen (CMD bleibt offen)", 118, 99, 200, 50)
$Icon2 = GUICtrlCreateIcon("Z:\*****\AutoIT\Shutdown\Approved.ico", -0, 62, 99, 50, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 3
$nMsg = GUIGetMsg (3)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button3_2
Exit
Case $Button3_1
WinKill(@WindowsDir & "\system32\cmd.exe")
Exit
EndSwitch
WEnd
EndFunc
Den Ruhezustand musste ich etwas anders bewergstelligen, da Windows es meinem Wissen nach nicht einfacher ermöglicht. Dafür ist der Ruhezustand der einzige Befehl, der funktioniert.
Falls jemandem ein schöner Weg einfällt, einen Countdown im GUI 2 anzuzeigen, wäre ich sehr dankbar. Ich habe viele Sachen ausprobiert und kam nicht einmal in die Nähe einer Lösung und habe deshalb drauf verzichtet
Danke schonmal
Grüße
Eggsplorer