[AutoIT] Process Manager

    Publicités

Users Who Are Viewing This Thread (Total: 0, Members: 0, Guests: 0)

Status
Not open for further replies.

n0way

Membre actif
Nov 21, 2010
311
0
581
Earth
Process Manager

Alors voilà, j'ai programmé ce petit truc sous AutoIT bien utile, cela permet de programmer un lancement de 5 programmes "maxi" lors de votre absence...

et lors de votre retour ils se referment tout bétement...

Ca permet de programmer uTorrent, et d'autres trucs a votre choix, lors de votre absence.

C'est encore que la version béta, mais j’espère améliorer ceci ensuite.

Les logiciels se lancent au bout de 10mins d'absence !

PHP:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Process.au3>
#include <Timers.au3>

;--------- variable ----------

Global $inifile = @WorkingDir & "\config.ini"
$var = 0
$mousex = 0
$mousey = 0
$IdleMinimum = 600000


Opt("TrayMenuMode", 0)
TrayTip("Process Manager v1.0b", "is loaded.", 30)

;--------- GUI ---------------


Global $Form1 = GUICreate("Process Manager", 449, 255, 192, 124)
GUISetIcon("icone\devico.ico")
GUISetFont(9, 400, 0, "Tahoma")

Global $Label1 = GUICtrlCreateLabel("Process Manager", 176, 8, 116, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")

Global $Saisie1 = GUICtrlCreateInput("Chemin d'accès du programme", 8, 56, 249, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
Global $ButtonPAR1 = GUICtrlCreateButton("Parcourir", 272, 54, 75, 25, $WS_GROUP)
Global $ButtonON1 = GUICtrlCreateButton("ON", 360, 54, 75, 25, $WS_GROUP)

Global $Saisie2 = GUICtrlCreateInput("Chemin d'accès du programme", 8, 96, 249, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
Global $ButtonPAR2 = GUICtrlCreateButton("Parcourir", 272, 94, 75, 25, $WS_GROUP)
Global $ButtonON2 = GUICtrlCreateButton("ON", 360, 94, 75, 25, $WS_GROUP)

Global $Saisie3 = GUICtrlCreateInput("Chemin d'accès du programme", 8, 136, 249, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
Global $ButtonPAR3 = GUICtrlCreateButton("Parcourir", 272, 134, 75, 25, $WS_GROUP)
Global $ButtonON3 = GUICtrlCreateButton("ON", 360, 134, 75, 25, $WS_GROUP)

Global $Saisie4 = GUICtrlCreateInput("Chemin d'accès du programme", 8, 176, 249, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
Global $ButtonPAR4 = GUICtrlCreateButton("Parcourir", 272, 174, 75, 25, $WS_GROUP)
Global $ButtonON4 = GUICtrlCreateButton("ON", 360, 174, 75, 25, $WS_GROUP)

Global $Saisie5 = GUICtrlCreateInput("Chemin d'accès du programme", 8, 216, 249, 22, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
Global $ButtonPAR5 = GUICtrlCreateButton("Parcourir", 272, 214, 75, 25, $WS_GROUP)
Global $ButtonON5 = GUICtrlCreateButton("ON", 360, 214, 75, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

;-------------- Charger le fichier .ini --------------

if Not FileExists($inifile) Then
	_FileCreate($inifile)
	IniWriteSection($inifile, "Process1", "dir=" & @LF & "proc=" & @LF & "on=" & @LF & @LF)
	IniWriteSection($inifile, "Process2", "dir=" & @LF & "proc=" & @LF & "on=" & @LF & @LF)
	IniWriteSection($inifile, "Process3", "dir=" & @LF & "proc=" & @LF & "on=" & @LF & @LF)
	IniWriteSection($inifile, "Process4", "dir=" & @LF & "proc=" & @LF & "on=" & @LF & @LF)
	IniWriteSection($inifile, "Process5", "dir=" & @LF & "proc=" & @LF & "on=" & @LF & @LF)
	Sleep(2000)
EndIf

if IniRead($inifile, "Process1", "dir", "") <> "" Then
	GuiCtrlSetData($Saisie1, IniRead($inifile, "Process1", "dir", ""))

	if IniRead($inifile, "Process1", "on", "") = 1 Then
		GuiCtrlSetBkColor($Saisie1, 0x008000)
		GuiCtrlSetData($ButtonON1, "OFF")
	EndIf
	if Iniread($inifile, "Process1", "on", "") = 0 Then
		GuiCtrlSetBkColor($Saisie1, 0x800000)
	EndIf

EndIf

if IniRead($inifile, "Process2", "dir", "") <> "" Then
	GuiCtrlSetData($Saisie2, IniRead($inifile, "Process2", "dir", ""))

	if IniRead($inifile, "Process2", "on", "") = 1 Then
		GuiCtrlSetBkColor($Saisie2, 0x008000)
		GuiCtrlSetData($ButtonON2, "OFF")
	EndIf
	if Iniread($inifile, "Process2", "on", "") = 0 Then
		GuiCtrlSetBkColor($Saisie2, 0x800000)
	EndIf

EndIf

if IniRead($inifile, "Process3", "dir", "") <> "" Then
	GuiCtrlSetData($Saisie3, IniRead($inifile, "Process3", "dir", ""))

	if IniRead($inifile, "Process3", "on", "") = 1 Then
		GuiCtrlSetBkColor($Saisie3, 0x008000)
		GuiCtrlSetData($ButtonON3, "OFF")
	EndIf
	if Iniread($inifile, "Process3", "on", "") = 0 Then
		GuiCtrlSetBkColor($Saisie3, 0x800000)
	EndIf

EndIf

if IniRead($inifile, "Process4", "dir", "") <> "" Then
	GuiCtrlSetData($Saisie4, IniRead($inifile, "Process4", "dir", ""))

	if IniRead($inifile, "Process4", "on", "") = 1 Then
		GuiCtrlSetBkColor($Saisie4, 0x008000)
		GuiCtrlSetData($ButtonON4, "OFF")
	EndIf
	if Iniread($inifile, "Process4", "on", "") = 0 Then
		GuiCtrlSetBkColor($Saisie4, 0x800000)
	EndIf

EndIf

if IniRead($inifile, "Process5", "dir", "") <> "" Then
	GuiCtrlSetData($Saisie5, IniRead($inifile, "Process5", "dir", ""))

	if IniRead($inifile, "Process5", "on", "") = 1 Then
		GuiCtrlSetBkColor($Saisie5, 0x008000)
		GuiCtrlSetData($ButtonON5, "OFF")
	EndIf
	if Iniread($inifile, "Process5", "on", "") = 0 Then
		GuiCtrlSetBkColor($Saisie5, 0x800000)
	EndIf

EndIf

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

;------------- PARCOURIR ----------------;

		Case $ButtonPAR1
			$src = FileOpenDialog("Chemin de l'éxecutable", @ProgramFilesDir, "Executable (*.exe)", 1)
			if Not $src = "" Then
				$file = StringSplit($src, "\")
				GuiCtrlSetData($Saisie1, $src)
				IniWrite($inifile, "Process1", "dir", $src)
				IniWrite($inifile, "Process1", "proc", $file[$file[0]])
			EndIf
		Case $ButtonPAR2
			$src = FileOpenDialog("Chemin de l'éxecutable", @ProgramFilesDir, "Executable (*.exe)", 1)
			if Not $src = "" Then
				$file = StringSplit($src, "\")
				GuiCtrlSetData($Saisie2, $src)
				IniWrite($inifile, "Process2", "dir", $src)
				IniWrite($inifile, "Process2", "proc", $file[$file[0]])
			EndIf
		Case $ButtonPAR3
			$src = FileOpenDialog("Chemin de l'éxecutable", @ProgramFilesDir, "Executable (*.exe)", 1)
			if Not $src = "" Then
				$file = StringSplit($src, "\")
				GuiCtrlSetData($Saisie3, $src)
				IniWrite($inifile, "Process3", "dir", $src)
				IniWrite($inifile, "Process3", "proc", $file[$file[0]])
			EndIf
		Case $ButtonPAR4
			$src = FileOpenDialog("Chemin de l'éxecutable", @ProgramFilesDir, "Executable (*.exe)", 1)
			if Not $src = "" Then
				$file = StringSplit($src, "\")
				GuiCtrlSetData($Saisie4, $src)
				IniWrite($inifile, "Process4", "dir", $src)
				IniWrite($inifile, "Process4", "proc", $file[$file[0]])
			EndIf
		Case $ButtonPAR5
			$src = FileOpenDialog("Chemin de l'éxecutable", @ProgramFilesDir, "Executable (*.exe)", 1)
			if Not $src = "" Then
				$file = StringSplit($src, "\")
				GuiCtrlSetData($Saisie5, $src)
				IniWrite($inifile, "Process5", "dir", $src)
				IniWrite($inifile, "Process5", "proc", $file[$file[0]])
			EndIf

;-------------- ON / OFF ----------------

		Case $ButtonON1
			if GuiCTrlRead($Saisie1) <> "Chemin d'accès du programme" Then

				if GuiCtrlRead($ButtonON1) = "ON" Then
					GUICtrlSetBkColor($Saisie1, 0x008000)
					GuiCtrlSetData($ButtonON1, "OFF")
					IniWrite($inifile, "Process1", "on", "1")
				Else
					GUICtrlSetBkColor($Saisie1, 0x800000)
					GuiCtrlSetData($ButtonON1, "ON")
					IniWrite($inifile, "Process1", "on", "0")
				EndIf
			Else
				msgBox(1, "Erreur", "Tu n'a pas spécifié d'éxécutable")
			EndIf

		Case $ButtonON2
			if GuiCTrlRead($Saisie2) <> "Chemin d'accès du programme" Then

				if GuiCtrlRead($ButtonON2) = "ON" Then
					GUICtrlSetBkColor($Saisie2, 0x008000)
					GuiCtrlSetData($ButtonON2, "OFF")
					IniWrite($inifile, "Process2", "on", "1")
				Else
					GUICtrlSetBkColor($Saisie2, 0x800000)
					GuiCtrlSetData($ButtonON2, "ON")
					IniWrite($inifile, "Process2", "on", "0")
				EndIf
			Else
				msgBox(1, "Erreur", "Tu n'a pas spécifié d'éxécutable")
			EndIf

		Case $ButtonON3
			if GuiCTrlRead($Saisie3) <> "Chemin d'accès du programme" Then

				if GuiCtrlRead($ButtonON3) = "ON" Then
					GUICtrlSetBkColor($Saisie3, 0x008000)
					GuiCtrlSetData($ButtonON3, "OFF")
					IniWrite($inifile, "Process3", "on", "1")
				Else
					GUICtrlSetBkColor($Saisie3, 0x800000)
					GuiCtrlSetData($ButtonON3, "ON")
					IniWrite($inifile, "Process3", "on", "0")
				EndIf
			Else
				msgBox(1, "Erreur", "Tu n'a pas spécifié d'éxécutable")
			EndIf

		Case $ButtonON4
			if GuiCTrlRead($Saisie4) <> "Chemin d'accès du programme" Then

				if GuiCtrlRead($ButtonON4) = "ON" Then
					GUICtrlSetBkColor($Saisie4, 0x008000)
					GuiCtrlSetData($ButtonON4, "OFF")
					IniWrite($inifile, "Process4", "on", "1")
				Else
					GUICtrlSetBkColor($Saisie4, 0x800000)
					GuiCtrlSetData($ButtonON4, "ON")
					IniWrite($inifile, "Process4", "on", "0")
				EndIf
			Else
				msgBox(1, "Erreur", "Tu n'a pas spécifié d'éxécutable")
			EndIf

		Case $ButtonON5
			if GuiCTrlRead($Saisie5) <> "Chemin d'accès du programme" Then

				if GuiCtrlRead($ButtonON5) = "ON" Then
					GUICtrlSetBkColor($Saisie5, 0x008000)
					GuiCtrlSetData($ButtonON5, "OFF")
					IniWrite($inifile, "Process5", "on", "1")
				Else
					GUICtrlSetBkColor($Saisie5, 0x800000)
					GuiCtrlSetData($ButtonON5, "ON")
					IniWrite($inifile, "Process5", "on", "0")
				EndIf
			Else
				msgBox(1, "Erreur", "Tu n'a pas spécifié d'éxécutable")
			EndIf




	EndSwitch

	;------------- IDLE CHECKER AND ACTIONNER ------------;

	If _Timer_GetIdleTime() >= $IdleMinimum Then

		$proc1on = iniRead($inifile, "Process1", "on", "")
		$proc2on = iniRead($inifile, "Process2", "on", "")
		$proc3on = iniRead($inifile, "Process3", "on", "")
		$proc4on = iniRead($inifile, "Process4", "on", "")
		$proc5on = iniRead($inifile, "Process5", "on", "")
		$proc1 = iniRead($inifile, "Process1", "proc", "")
		$proc2 = iniRead($inifile, "Process2", "proc", "")
		$proc3 = iniRead($inifile, "Process3", "proc", "")
		$proc4 = iniRead($inifile, "Process4", "proc", "")
		$proc5 = iniRead($inifile, "Process5", "proc", "")

		$var = 1
		$mousex = MouseGetPos(0)
		$mousey = MouseGetPos(1)


		If $proc1on = 1 Then
				ShellExecute(iniRead($inifile, "Process1", "dir", ""))
		EndIf

		If $proc2on = 1 Then
				ShellExecute(iniRead($inifile, "Process2", "dir", ""))
		EndIf

		if $proc3on = 1 Then
				ShellExecute(iniRead($inifile, "Process3", "dir", ""))
		EndIf

		if $proc4on = 1 Then
				ShellExecute(iniRead($inifile, "Process4", "dir", ""))
		EndIf


		if $proc5on = 1 Then
				ShellExecute(iniRead($inifile, "Process5", "dir", ""))
		EndIf


		Do
			Sleep(20)
		Until _Timer_GetIdleTime() < $IdleMinimum
	EndIf
	Sleep(20)

	If $var = 1 And $mousex <> MouseGetPos(0) And $mousey <> MouseGetPos(1) Then
		If ProcessExists($proc1) Then
			ProcessClose($proc1)
		EndIf

		If ProcessExists($proc2) Then
			ProcessClose($proc2)
		EndIf

		If ProcessExists($proc3) Then
			ProcessClose($proc3)
		EndIf

		If ProcessExists($proc4) Then
			ProcessClose($proc4)
		EndIf

		If ProcessExists($proc5) Then
			ProcessClose($proc5)
		EndIf


	EndIf
WEnd

Vous pouvez télécharger : Ce lien n'est pas visible, veuillez vous connecter pour l'afficher. Je m'inscris!

UN MERCI NE COUTE RIEN
 

Attachments

  • Process Manager.rar
    299.9 KB · Views: 2
Last edited:

Evaelis

La Voix de la Sagesse
V
Ancien staff
Apr 28, 2010
22,949
468
1,699
Valhalla
msgBox(1, "Erreur", "Tu n'a pas spécifié déxécutable")
Cette faute est superbe :)
 
Status
Not open for further replies.