Hallo, endlich ist das Script für die Schule fertig. habt ihr verbesserungsvorschläge, und was haltet ihr von dem script? Angehängt sind benötigte zusatzdateien für das Lehrer prog.
führ lehrer:
Spoiler anzeigen
,
#include <Array.au3>
;~ Includes
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3> ;<- Für Combolist
#include <inet.au3> ;<- zum prüfen ob PChostname die endung le hat
#include <Misc.au3> ;<- zum prüfen, ob Programm bereits läüft
;testen, ob Programm bereits läuft.Wenn ja: Hinweis darauf und beenden
If _Singleton("Skript", 1) = 0 Then
MsgBox(64, "MasterControl", "MasterControl läuft bereits", 5)
Exit
EndIf
; teste, ob Programm auf Lehrer PC ausgeführt wird. Wenn nicht: Meldung + Beenden
TCPStartup()
$hostname = _TCPIpToName(@IPAddress1)
$hostnametest = StringSplit($hostname, "-")
If $hostnametest[0] = 3 Then ;wenn im hostname 3 - vorhanden sind dann
[/autoit] [autoit][/autoit] [autoit]If $hostnametest[3] <> "le" Then
MsgBox(64, "MasterControl", "Dieses Programm darf nur auf Lehrerrechnern ausgeführt werden")
Exit
EndIf
If $hostnametest[3] <> "LE" Then
MsgBox(64, "MasterControl", "Dieses Programm darf nur auf Lehrerrechnern ausgeführt werden")
Exit
EndIf
Else ; wenn im hostname keine 2 - vorhanden sind
MsgBox(64, "MasterControl", "Dieses Programm sollte auf einem Lehrerrechner der Schule ausgeführt werden")
EndIf
TCPShutdown()
$pcsinraum = IniRead(@ScriptDir & "\einstellungen.ini", "infos", "pcs", "0")
$raumnummer = IniRead(@ScriptDir & "\einstellungen.ini", "infos", "raum", "0")
;~ Hier startet der GUI-Code
$Gui = GUICreate("MasterControl 1.0 BETA", 350, 320); <-- Erstelle die GUI
GUICtrlCreateLabel("Auswahl der PCs", 10, 20)
; checkboxen zum PCs auswählen
Dim $pc[$pcsinraum + 1]
Dim $pcip[$pcsinraum + 1]
Dim $verbindung[$pcsinraum + 1]
Dim $datenpcfenster[$pcsinraum + 1]
For $i = 1 To $pcsinraum
$pc[$i] = GUICtrlCreateCheckbox($i, 10 + ((($i > 10) + ($i > 20)) * 40), 30 + ($i - (($i > (($i > 20) + 1) * 10) * (($i > 20) + 1) * 10)) * 20)
Next
$prozentproschritt = 100 / $pcsinraum
[/autoit] [autoit][/autoit] [autoit]GUISetState(@SW_SHOW)
[/autoit] [autoit][/autoit] [autoit];copyright
GUICtrlCreateLabel("© Copyright Alexander Imka", 120, 295)
;Icon setzten
If FileExists(@ScriptDir & "\icon.ico") Then
GUISetIcon(@ScriptDir & "\icon.ico")
Else
MsgBox(48, "Icon fehlt", "Das Icon wurde nicht gefunden. Das Programm wird ohne das Icon weiter ausgeführt!")
EndIf
;trennlinie
If $pcsinraum < 21 Then GUICtrlCreatePic("linie.jpg", 100, 5, 2, 310)
$Buttonuebernehmen = GUICtrlCreateButton("Übernehmen", 5, 295, 90, 25, $WS_GROUP)
$Buttonalle = GUICtrlCreateButton("alle", 55, 265, 40, 25, $WS_GROUP)
$buttonkeinen = GUICtrlCreateButton("keinen", 5, 265, 40, 25, $WS_GROUP)
;Combolist
$combo = GUICtrlCreateCombo("", 120, 10, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Reboot|Sperren|Fenster|MsgBox")
$combobutton = GUICtrlCreateButton("wechseln", 270, 10, 65, 20, $WS_GROUP)
; --- --- --- --- Funktionenen --- --- --- ---
;Reboot
$neustart = GUICtrlCreateButton("Neustarten", 120, 100, 100, 50, $WS_GROUP)
$herunterfahren = GUICtrlCreateButton("Herunterfahren", 120, 150, 100, 50, $WS_GROUP)
$abmelden = GUICtrlCreateButton("Abmelden", 230, 100, 100, 50, $WS_GROUP)
$standby = GUICtrlCreateButton("Standby", 230, 150, 100, 50, $WS_GROUP)
GUICtrlSetState($neustart, $GUI_HIDE)
GUICtrlSetState($herunterfahren, $GUI_HIDE)
GUICtrlSetState($abmelden, $GUI_HIDE)
GUICtrlSetState($standby, $GUI_HIDE)
;MsgBox
$msgboxicon1 = GUICtrlCreateIcon("shell32.dll", 263, 120, 70)
$msgboxicon2 = GUICtrlCreateIcon("shell32.dll", 240, 170, 70)
GUICtrlSetState($msgboxicon1, $GUI_HIDE)
GUICtrlSetState($msgboxicon2, $GUI_HIDE)
$msgboxlabel1 = GUICtrlCreateLabel("1", 151, 72)
$msgboxlabel2 = GUICtrlCreateLabel("2", 210, 72)
$msgboxlabel3 = GUICtrlCreateLabel("Icon wählen:", 120, 40)
$msgboxlabel4 = GUICtrlCreateLabel("Text eingeben:", 120, 120)
GUICtrlSetState($msgboxlabel1, $GUI_HIDE)
GUICtrlSetState($msgboxlabel2, $GUI_HIDE)
GUICtrlSetState($msgboxlabel3, $GUI_HIDE)
GUICtrlSetState($msgboxlabel4, $GUI_HIDE)
$msgboxinhalt = GUICtrlCreateInput("", 112, 150, 228)
GUICtrlSetState($msgboxinhalt, $GUI_HIDE)
$iconwahl1 = GUICtrlCreateRadio("Icon1", 230, 70)
$iconwahl2 = GUICtrlCreateRadio("Icon2", 230, 90)
GUICtrlSetState($iconwahl1, $GUI_HIDE)
GUICtrlSetState($iconwahl2, $GUI_HIDE)
$msgboxsenden = GUICtrlCreateButton("Senden", 174, 200, 100, 50)
GUICtrlSetState($msgboxsenden, $GUI_HIDE)
For $i = 1 To $pcsinraum
$pcip[$i] = "10.20.0.254"
Next
;hostnames zu ips
If $hostnametest[0] = 3 Then
ProgressOn("IP ermitteln", "Die IP's werden ermittelt")
TCPStartup()
For $i = 1 To $pcsinraum
$r = StringFormat("_%02u%", $i)
ProgressSet($prozentproschritt * $i, "Rechner " & $i & " / " & $pcsinraum, "Die IP's werden ermittelt")
If Ping("wks-" & $raumnummer & "-" & $r, 50) Then $pcip[$i] = TCPNameToIP("wks-" & $raumnummer & "-" & $r)
Next
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]TCPShutdown()
ProgressOff()
EndIf
;sperren
$sperreneingabe = GUICtrlCreateButton("Eingabe sperren", 120, 100, 100, 50, $WS_GROUP)
$sperrenbildschirm = GUICtrlCreateButton("Bildschirm sperren", 120, 150, 100, 50, $WS_GROUP)
$entsperreneingabe = GUICtrlCreateButton("Eingabe freigeben", 230, 100, 100, 50, $WS_GROUP)
$entsperrenbildschirm = GUICtrlCreateButton("Bildschirm freigeben", 230, 150, 100, 50, $WS_GROUP)
GUICtrlSetState($sperreneingabe, $GUI_HIDE)
GUICtrlSetState($sperrenbildschirm, $GUI_HIDE)
GUICtrlSetState($entsperreneingabe, $GUI_HIDE)
GUICtrlSetState($entsperrenbildschirm, $GUI_HIDE)
; Fenster
[/autoit] [autoit][/autoit] [autoit]$aktualisieren = GUICtrlCreateButton("Aktualisieren", 120, 35, 230, 20, $WS_GROUP)
GUICtrlSetState($aktualisieren, $GUI_HIDE)
; --- --- --- ---Ende Funktionen --- --- --- ---
[/autoit] [autoit][/autoit] [autoit];starticon
$starticon = GUICtrlCreateIcon("shell32.dll", 19, 200, 150);starticon
GUISetState($starticon, $GUI_HIDE)
UDPStartup()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While 1 ; <-- Endlosschleife anfangen
[/autoit] [autoit][/autoit] [autoit]$nMsg = GUIGetMsg(); <-- Fange die Button-Events ab
Switch $nMsg ;<-- Unterscheide die Events
Case $GUI_EVENT_CLOSE ; <-- Wenn GUI geschlossen wird dann
UDPShutdown()
Exit ; <-- Skript beenden
Case $Buttonuebernehmen
ProgressOn("Bitte warten...", "Verbindungen werden hergestellt")
For $i = 1 To $pcsinraum
[/autoit] [autoit][/autoit] [autoit]If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
$verbindung[$i] = UDPBind($pcip[$i], 2000)
Else
ToolTip("PC " & $i & " ist nicht erreichbar")
Sleep(1000)
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
ProgressSet($prozentproschritt * $i, $i & "/" & $pcsinraum)
Sleep(200)
Next
ToolTip("")
ProgressOff()
Case $Buttonalle
For $i = 1 To $pcsinraum
GUICtrlSetState($pc[$i], $GUI_CHECKED)
Next
Case $buttonkeinen
For $i = 1 To $pcsinraum
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
Next
Case $combobutton
If GUICtrlRead($combo) = "Reboot" Then
GUICtrlSetState($neustart, $GUI_SHOW)
GUICtrlSetState($herunterfahren, $GUI_SHOW)
GUICtrlSetState($abmelden, $GUI_SHOW)
GUICtrlSetState($standby, $GUI_SHOW)
Else
GUICtrlSetState($neustart, $GUI_HIDE)
GUICtrlSetState($herunterfahren, $GUI_HIDE)
GUICtrlSetState($abmelden, $GUI_HIDE)
GUICtrlSetState($standby, $GUI_HIDE)
EndIf
If GUICtrlRead($combo) = "" Then
GUICtrlSetState($starticon, $GUI_SHOW)
Else
GUICtrlSetState($starticon, $GUI_HIDE)
EndIf
[/autoit] [autoit][/autoit] [autoit]If GUICtrlRead($combo) = "MsgBox" Then
GUICtrlSetState($msgboxicon1, $GUI_SHOW)
GUICtrlSetState($msgboxicon2, $GUI_SHOW)
GUICtrlSetState($msgboxlabel1, $GUI_SHOW)
GUICtrlSetState($msgboxlabel2, $GUI_SHOW)
GUICtrlSetState($iconwahl1, $GUI_SHOW)
GUICtrlSetState($iconwahl2, $GUI_SHOW)
GUICtrlSetState($msgboxlabel3, $GUI_SHOW)
GUICtrlSetState($msgboxlabel4, $GUI_SHOW)
GUICtrlSetState($msgboxinhalt, $GUI_SHOW)
GUICtrlSetState($msgboxsenden, $GUI_SHOW)
Else
GUICtrlSetState($msgboxicon1, $GUI_HIDE)
GUICtrlSetState($msgboxicon2, $GUI_HIDE)
GUICtrlSetState($msgboxlabel1, $GUI_HIDE)
GUICtrlSetState($msgboxlabel2, $GUI_HIDE)
GUICtrlSetState($iconwahl1, $GUI_HIDE)
GUICtrlSetState($iconwahl2, $GUI_HIDE)
GUICtrlSetState($msgboxlabel3, $GUI_HIDE)
GUICtrlSetState($msgboxlabel4, $GUI_HIDE)
GUICtrlSetState($msgboxinhalt, $GUI_HIDE)
GUICtrlSetState($msgboxsenden, $GUI_HIDE)
EndIf
[/autoit] [autoit][/autoit] [autoit]If GUICtrlRead($combo) = "Sperren" Then
GUICtrlSetState($sperreneingabe, $GUI_SHOW)
GUICtrlSetState($sperrenbildschirm, $GUI_SHOW)
GUICtrlSetState($entsperreneingabe, $GUI_SHOW)
GUICtrlSetState($entsperrenbildschirm, $GUI_SHOW)
Else
GUICtrlSetState($sperreneingabe, $GUI_HIDE)
GUICtrlSetState($sperrenbildschirm, $GUI_HIDE)
GUICtrlSetState($entsperreneingabe, $GUI_HIDE)
GUICtrlSetState($entsperrenbildschirm, $GUI_HIDE)
EndIf
[/autoit] [autoit][/autoit] [autoit]If GUICtrlRead($combo) = "Fenster" Then
GUICtrlSetState($aktualisieren, $GUI_SHOW)
Else
GUICtrlSetState($aktualisieren, $GUI_HIDE)
EndIf
;;; Winlist ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case $aktualisieren
$standartheight = 50
ProgressOn("Bitte warten...", "Infos werden abgerufen")
For $i = 1 To $pcsinraum
If Ping($pcip[$i]) Then
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
UDPSend($verbindung[$i], "ip#" & @IPAddress1)
Sleep(50)
UDPSend($verbindung[$i], "fensteranfrage")
While 1
$datenpcfenster[$i] = UDPRecv($verbindung[$i], 50000)
If $datenpcfenster[$i] <> "" Then ExitLoop
ToolTip("warte auf PC " & $i)
WEnd
ToolTip("")
$pcfenster1 = StringSplit($datenpcfenster[$i], "#")
For $x = 2 To $pcfenster1[0]
GUICtrlCreateLabel($pcfenster1, 120, $standartheight)
$standartheight += 10
Next
EndIf
EndIf
ProgressSet($prozentproschritt * $i, "")
Next
ProgressOff()
;;; Reboot ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case $neustart
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "neustart")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Case $abmelden
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "abmelden")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Case $herunterfahren
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "herunterfahren")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Case $standby
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "standby")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
;;;sperren;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[/autoit] [autoit][/autoit] [autoit]Case $sperreneingabe
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "sperreneingabe")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Case $sperrenbildschirm
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "sperrenbildschirm")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Case $entsperreneingabe
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "entsperreneingabe")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Case $entsperrenbildschirm
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
UDPSend($verbindung[$i], "entsperrenbildschirm")
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
;;;MsgBox;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[/autoit] [autoit][/autoit] [autoit]Case $msgboxsenden
If $msgboxinhalt <> "" Then
ProgressOn("bitte warten...", "Aktion wird ausgeführt")
For $i = 1 To $pcsinraum
If GUICtrlRead($pc[$i]) = $GUI_CHECKED Then
If Ping($pcip[$i]) Then
If $iconwahl1 = $GUI_CHECKED Then
$icon = 64
Else
If $iconwahl2 = $GUI_CHECKED Then
$icon = 16
Else
$icon = 0
EndIf
EndIf
UDPSend($verbindung[$i], "msgbox#" & $icon & "#" & $msgboxinhalt)
ProgressSet($prozentproschritt * $i, "")
Else
GUICtrlSetState($pc[$i], $GUI_UNCHECKED)
EndIf
EndIf
Next
ProgressOff()
Else
MsgBox(48, "", "Bitte Text eingeben")
EndIf
EndSwitch
WEnd ; <-- Beginne Schleife von Vorne;### Tidy Error -> while is never closed in your script.
[/autoit]
für Clients:
Spoiler anzeigen
;feststellen des Scriptpfadt
$scriptpfad = @ScriptDir & "\" & @ScriptName
;setzen der Testvariable
$regtest = 0
; überprüfen ob Schlüssel besteht und gegebenenfalls schreiben
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","MasterControl")
if not @error then $regtest = 1
if $regtest = 0 Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","MasterControl","REG_SZ",$scriptpfad)
if @error Then MsgBox(48,"Fehler","Felher beim Schreiben in die Regitery")
;TCP und UDP Starten
UDPStartup
;verbindungen zulassen
$lehrer = UDPBind(@IPAddress1,2000)
;infos über pc standort abfragen, um winlist an lehrer zu schiken
$lehrerip = "10.20.0.254"
;Schleife um auf befehle zu warten
while 1
Sleep(10)
$ankommenderbefehl = UDPRecv($lehrer,1000)
$befehl = StringSplit($ankommenderbefehl,"#")
if $befehl[0] = 3 Then MsgBox($befehl[2],"Merke auf:",$befehl[3])
if $befehl[0] = 2 Then $lehrerip = $befehl[2]
if $befehl[1] = "herunterfahren" Then Shutdown (17)
if $befehl[1] = "neustart" Then Shutdown(6)
if $befehl[1] = "abmelden" Then Shutdown(16)
if $befehl[1] = "standby" Then Shutdown(48)
if $befehl[1] = "sperreneingabe" Then $eingabesperren = 1
if $befehl[1] = "sperrenbildschirm" Then $bildschirmsperren = 1
if $befehl[1] = "entsperreneingabe" Then $eingabesperren = 0
if $befehl[1] = "entsperrenbildschirm" Then $bildschirmsperren = 0
if $befehl[1] = "fensteranfrage" Then
EndIf
WEnd