#include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>
#RequireAdmin

If @OSVersion <> "WIN_7" then 
	MsgBox(16, "Fehler", "Dein Betriebssystem ist nicht Windows 7.")
	Exit
EndIf
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $ExitID

_Main()

Func _Main()
	Local $createID, $DeleteID

	GUICreate("Custom Msgbox", 300, 80)

	GUICtrlCreateLabel("Bitte wählen sie eine Aktion aus.  ", 10, 10)
	GUICtrlCreateLabel("Aktueller Status: ", 10, 30)
	If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") = 1 then
		GUICtrlCreateLabel(">Benutzerdifiniert< ", 100, 30)
	Else 
		GUICtrlCreateLabel(">Standart< ", 100, 30)
	EndIf
	$CreateID = GUICtrlCreateButton("Anmeldebildschirm verändern.", 10, 50)
	GUICtrlSetOnEvent($CreateID, "OnCreate")
	$DeleteID = GUICtrlCreateButton("Standart wiederherstellen.", 170, 50)
	GUICtrlSetOnEvent($DeleteID, "OnDelete")

	GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

	GUISetState() 

	While 1
		Sleep(1000)
	WEnd
EndFunc

Func OnDelete()
	RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground")
	If @error = 0 Then 
		MsgBox(16, "Fehler", "Registry-Wert konnte nicht gelöscht werden. Bitte manuell löschen." & @CRLF & "" & @CRLF & "Registry-Wert:" & @CRLF & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background\OEMBackground")
	Else
		MsgBox(0, "Info", "Registry-Wert erfolgreich gelöscht.")
	EndIf
EndFunc

Func OnExit()
	Exit
EndFunc

Func OnCreate()
	If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground" ) <> 1
		Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", "REG_DWORD", "1") and MsgBox(0, "Info", "Registry-Wert wurde erstellt")
		If @error <> 0 Then 
			MsgBox(16, "Fehler", "Registry-Wert konnte nicht erstellt werden!")
	Else 
		MsgBox(0, "Info", "Registry-Wert exsistiert berits!")
	Endif
	
	If FileExists(@HomeDrive & "\Windows\System32\oobe\info\backgrounds") Then
    MsgBox(4096, "Info", "Erforderliches Verzeichnis wurde erstellt.")
	Else
    DirCreate(@HomeDrive & "\Windows\System32\oobe\info\backgrounds")
	MsgBox(4096, "Info", "Erforderliches Verzeichnis existiert")
	EndIf
	$Bild = FileOpenDialog ( "Bitte Bild auswählen.", "@DesktopDir", "JPG-Bild (*.jpg)" , 1 )
	_GDIPlus_Startup()
	$BildL = _GDIPlus_ImageLoadFromFile($Bild)
	$X = _GDIPlus_ImageGetWidth ($BildL)
	$Y = _GDIPlus_ImageGetHeight ($BildL)
	If $X <> @DesktopWidth Then 
		MsgBox(16,"Error","Ihr Bild hat die falsche Breite") Exit
	EndIf
	If $Y <> @DesktopHeight Then 
		MsgBox(16,"Error","Ihr Bild hat die falsche Höhe") Exit
	EndIf
	If FileGetSize($Bild) > 262144 Then 
		MsgBox(16, "Fehler", "Bild ist zu groß (über 256 KB).") Exit
	EndIf
	
	MsgBox(48, "ACHTUNGG!", "Ihr bild wird verschoben. " & @CRLF & "Das Bild ist anschlisend nicht mehr im Quellverzeichniss vorhanden.")
	FileMove($Bild, @HomeDrive & "\Windows\System32\oobe\info\backgrounds\backgroundDefault.jpg" , 1)
	If @error <> 0 Then MsgBox(16, "Fehler", "Bild kann nicht kopiert werden.")
EndFunc