#NoTrayIcon
#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=D:\Meine Apps\tools\gfx\71.ico
#AutoIt3Wrapper_Outfile=WMPSC 2 res.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=Windows Media Player Style Changer mit res Datei
#AutoIt3Wrapper_Res_Description=Windows Media Player Style Changer mit res Datei
#AutoIt3Wrapper_Res_Fileversion=1.0.0.2
#AutoIt3Wrapper_Res_LegalCopyright=© ICE Tec. All rights reserved.
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_Field=CompanyName|ICE Tec
#AutoIt3Wrapper_Res_Field=OriginalFileName|WMPSC 2 res.exe
#AutoIt3Wrapper_Res_Field=ProductName|WMPSC
#AutoIt3Wrapper_Res_Field=ProductVersion|1.0.0.2
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <RansidTechno.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>


Global $workpath = @UserProfileDir & "\AppData\Local\Temp\WMPSC"
Global $respath = @UserProfileDir & "\AppData\Local\Temp\WMPSC\res\"
Global $DLLpath = @SystemDir & "\wmploc.DLL"
Global $DLLpath2 = @UserProfileDir & "\AppData\Local\Temp\wmploc.DLL"
Global $resDLL = @UserProfileDir & "\AppData\Local\Temp\res.DLL"
Global $backup = @UserProfileDir & "\AppData\Local\WMPSC\wmploc.res"
Global $backuppath = @UserProfileDir & "\AppData\Local\WMPSC"

Global $gui, $button_1, $button_2, $button_3, $button_4, $msg
$gui = GUICreate("WMPSC", 270, 140, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xFFAC01, $gui)
$label = GUICtrlCreateLabel("Wechsle den Style des WMP 12", 36, 10, 200, 15)
GUICtrlSetFont($label, 10, 700)
$button_1 = GUICtrlCreateButton("Installiere WMP 12 Theme", 20, 40, 230, 30)
GUICtrlSetFont($button_1, 9, 500)
$button_2 = GUICtrlCreateButton("WMP 12 Theme zurücksetzen", 20, 72, 230, 30)
GUICtrlSetFont($button_2, 9, 500)
$button_3 = GUICtrlCreateButton("Musik aus", 105, 110, 60, 20)
$button_4 = GUICtrlCreateButton("Musik an", 105, 110, 60, 20)
GUICtrlSetState($button_4, $GUI_HIDE)
GUISetState()

While 1
	$msg = GUIGetMsg()
	Select
		Case $msg = $GUI_EVENT_CLOSE
			_Exit()
			ExitLoop
		Case $msg = $button_1
			GUISetState(@SW_HIDE, $gui)
			_patch()
		Case $msg = $button_2
			GUISetState(@SW_HIDE, $gui)
			_restore()
		Case $msg = $button_3
			_StopSound()
			GUICtrlSetState($button_3, $GUI_HIDE)
			GUICtrlSetState($button_4, $GUI_SHOW)
		Case $msg = $button_4
			_PlaySound()
			GUICtrlSetState($button_4, $GUI_HIDE)
			GUICtrlSetState($button_3, $GUI_SHOW)
	EndSelect
WEnd

Func _patch()
	$_eWarten = GUICreate("Bitte warten Sie einem Moment", 363, 113, -1, -1, $WS_DLGFRAME)
	GUISetBkColor(0xFFFFFF)
	$_eProgress = GUICtrlCreateProgress(10, 48, 345, 25, $PBS_MARQUEE)
	GUICtrlCreateLabel("Bitte warten Sie, wmploc.DLL wird bearbeitet...", 55, 8, 265, 17)
	GUICtrlCreateLabel("Dies kann einige Zeit in Anspruch nehmen.", 55, 24, 300, 17)
	GUISetState(@SW_SHOW, $_eWarten)
	_Marquee($_eProgress, 1, 16)

	$hMenu = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $_eWarten, "int", 0)
	DllCall("user32.dll", "hwnd", "EnableMenuItem", "hwnd", $hMenu[0], "int", 0xF060, "int", 0x1)

	DirCreate($respath)
	FileInstall("D:\Meine Apps\tools\ResHacker.exe", $workpath & "\ResHacker.exe")
	FileInstall("D:\Meine Apps\tools\ResEdit.exe", $workpath & "\ResEdit.exe")
	FileInstall("D:\Meine Apps\tools\Agent_Orange.res", $respath & "Agent_Orange.res", 1)
	RunWait('takeown.exe /f ' & $DLLpath, @SystemDir, @SW_HIDE)
	RunWait('icacls.exe ' & $DLLpath & ' /grant *S-1-5-32-544:F /q', @SystemDir, @SW_HIDE)
	FileCopy($DLLpath, $DLLpath2)

	If Not FileExists($backup) Then
		DirCreate($backuppath)
		RunWait($workpath & '\ResHacker.exe -extract ' & $DLLpath2 & ', ' & $backup & ',,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $DLLpath2 & ', ' & $resDLL & ', AVI,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', JPGTYPE,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', MUI,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', ICONGROUP,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', XML,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', XMLWRITE,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', CURSORGROUP,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResHacker.exe -delete ' & $resDLL & ', ' & $resDLL & ', VERSIONINFO,,', $workpath, @SW_HIDE)
		RunWait($workpath & '\ResEdit.exe -convert "' & $resDLL & '" "' & $backup & '"', $workpath, @SW_HIDE) ; make res
		FileDelete($resDLL)
	EndIf

	RunWait($workpath & '\ResHacker.exe -modify ' & $DLLpath2 & ', ' & $DLLpath2 & ', ' & $respath & "Agent_Orange.res" & ',,,', $workpath, @SW_HIDE)

	RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager", "PendingFileRenameOperations", "REG_MULTI_SZ", "\??\" & $DLLpath2 & @LF & "!\??\" & $DLLpath)

	DirRemove($workpath, 1)
	GUIDelete($_eWarten)
	Local $iMsgBoxAnswer
	$iMsgBoxAnswer = MsgBox(68, "WMP 12 Theme Changer", "               WMP Theme geändert!" & @CRLF & "Muss PC Neu starten. Jetz PC Neu starten?")
	Select
		Case $iMsgBoxAnswer = 6 ;Yes
			_Exit()
			Shutdown(6)
			Exit
		Case $iMsgBoxAnswer = 7 ;No
			Sleep(150)
			GUISetState(@SW_SHOW, $gui)
	EndSelect
EndFunc   ;==>_patch


Func _restore()
	If FileExists($backup) Then
		$_eWarten = GUICreate("Bitte warten Sie einem Moment", 363, 113, -1, -1, $WS_DLGFRAME)
		GUISetBkColor(0xFFFFFF)
		$_eProgress = GUICtrlCreateProgress(10, 48, 345, 25, $PBS_MARQUEE)
		GUICtrlCreateLabel("Bitte warten Sie, wmploc.DLL wird bearbeitet...", 55, 8, 265, 17)
		GUICtrlCreateLabel("Dies kann einige Zeit in Anspruch nehmen.", 55, 24, 300, 17)
		GUISetState(@SW_SHOW, $_eWarten)
		_Marquee($_eProgress, 1, 16)

		$hMenu = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $_eWarten, "int", 0)
		DllCall("user32.dll", "hwnd", "EnableMenuItem", "hwnd", $hMenu[0], "int", 0xF060, "int", 0x1)

		DirCreate($workpath)
		FileInstall("D:\Meine Apps\tools\ResHacker.exe", $workpath & "\ResHacker.exe")
		FileCopy($DLLpath, $DLLpath2)
		RunWait($workpath & '\ResHacker.exe -modify ' & $DLLpath2 & ', ' & $DLLpath2 & ', ' & $backup & ',,,', $workpath, @SW_HIDE)
		RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager", "PendingFileRenameOperations", "REG_MULTI_SZ", "\??\" & $DLLpath2 & @LF & "!\??\" & $DLLpath)
		DirRemove($workpath, 1)
		DirRemove($backuppath, 1)
		GUIDelete($_eWarten)
		Local $iMsgBoxAnswer
		$iMsgBoxAnswer = MsgBox(68, "WMP 12 Theme Changer", "               WMP Theme geändert!" & @CRLF & "Muss PC Neu starten. Jetz PC Neu starten?")
		Select
			Case $iMsgBoxAnswer = 6 ;Yes
				_Exit()
				Shutdown(6)
				Exit
			Case $iMsgBoxAnswer = 7 ;No
				Sleep(150)
				GUISetState(@SW_SHOW, $gui)
		EndSelect
	Else
		MsgBox(4096, "", "Keine Backup res gefunden!")
	EndIf
EndFunc   ;==>_restore


Func _Marquee($h_Progress, $f_Mode = 1, $i_Time = 100)
	Local Const $WM_USER = 0x0400
	Local Const $PBM_SETMARQUEE = ($WM_USER + 10)
	Local $var = GUICtrlSendMsg($h_Progress, $PBM_SETMARQUEE, $f_Mode, Number($i_Time))
	If $var = 0 Then
		SetError(1)
		Return 0
	Else
		SetError(0)
		Return $var
	EndIf
EndFunc   ;==>_Marquee

