[..]Besoin de correction

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
JujuBois91
Niveau 1
Niveau 1
Messages : 11
Enregistré le : jeu. 15 juin 2017 10:08
Status : Hors ligne

[..]Besoin de correction

#1

Message par JujuBois91 »

Bonjour à tous

Je début dans AutoIT, j'aurai besoin d'aider de correction et optimisation d'un script que j essai de faire

Ci-dessous ce dernier, est il possible de m aider ?
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>

P4B()


Func P4B()

   GUIRegisterMsg($WM_PAINT, "_WM_PAINT")
   ; Load PNG image
   _GDIPlus_StartUp()
   $hLow   = _GDIPlus_ImageLoadFromFile(@scriptdir & "\low.png")
   $hHigh   = _GDIPlus_ImageLoadFromFile(@scriptdir & "\high.png")





; Crée une GUI avec différents contrôles.
Local $hGUI = GUICreate("Launcher Play4Bridge", 300, 200 ,-1, -1,-1, $WS_EX_TOPMOST)

$LabelDHCP = GUICtrlCreateLabel("",150, 90, 15, 15)
$LabelP4B = GUICtrlCreateLabel("",150, 110, 15, 15)



GUISetState()



$hPic_background = GUICtrlCreatePic(@scriptdir & "\logo.jpg", 0, 0, 300, 200)

GUICtrlSetState($hPic_background, $GUI_DISABLE)



   Local $idDHCP = GUICtrlCreateButton("GO DHCP", 110, 170, 60, 25)
    Local $idP4B = GUICtrlCreateButton("GO P4B", 170, 170, 60, 25)
    Local $idClose = GUICtrlCreateButton("Close All", 230, 170, 60, 25)
   Local $StatusDHCP = 2;
   Local $StatusP4B = 2;
    Local $NomCarteResoCurrent = "0";
   Local $ipcurrent = "255.255.255.255";
   Local $NomSSIDCurrent = "0";
   Local $iPIDDHCP = 0;
   Local $iPIDP4B = 0;
    Local $fin = 0

    $LabelTXTDHCP = GUICtrlCreateLabel("DHCP not starting", 10, 90)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Arrière plan du label transparent
    $LabelTXTP4B = GUICtrlCreateLabel("P4B not starting", 10, 110)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Arrière plan du label transparent

   $LabelReso = GUICtrlCreateLabel("[000000001] Dell Wireless 1560 802.11ac", 10, 30);
   GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Arrière plan du label transparent

   $LabelIp = GUICtrlCreateLabel("255.255.255.255", 10, 50);
   GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Arrière plan du label transparent

   $LabelSsid = GUICtrlCreateLabel("Play4Bridge", 10, 70);
   GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Arrière plan du label transparent



    $idMsg = GUIGetMsg()




; Boucle jusqu'à ce que l'utilisateur quitte.
    While $fin = 0


       if ($idMsg = $GUI_EVENT_CLOSE) or ($idMsg = $idClose) Then

         $return_value = MsgBox(262144+48+4,"Shutting Down", "Etes vous sûr de vouloir stopper tous les services P4B",10 )
         Switch $return_value
         case 1 ;OK ---> Flags: 0, 1
         MsgBox(0, "Return Value", "OK")
         case 2 ;cancel ---> Flags: 1, 3, 5, 6
         MsgBox(0, "Return Value", "Cancel")
         case 3 ;abort ---> Flags: 2
         MsgBox(0, "Return Value", "Abort")
         case 4 ;retry ---> Flags: 2, 5
         MsgBox(0, "Return Value", "Retry")
         case 5 ;Ignore ---> Flags: 2
         MsgBox(0, "Return Value", "Ignore")
         case 6 ;Yes ---> Flags: 3, 4
            ;Supprime la GUI précédente et tous ses contrôles.
              GUIDelete($hGUI)

            ; Ferme le processus
              If $iPIDDHCP > 0 Then ProcessClose($iPIDDHCP)
              If $iPIDP4B > 0 Then ProcessClose($iPIDP4B)
              $fin = 1
         case 7 ;No ---> Flags: 3, 4


EndSwitch


       Endif


        If $idMsg = $idDHCP Then
               If ProcessExists("tftpd64.exe") Then ; Vérifie si le processus Notepad est en cours d'exécution.

            EndIf
             Local $iPIDDHCP = Run ("C:\Users\Julien\MyDeltaSyncBox\Projet\Delta\Play4Bridge\tftpd64.460\tftpd64.exe")

       EndIf
           If $idMsg = $idP4B Then
               If ProcessExists("UwAmp.exe") Then ; Vérifie si le processus Notepad est en cours d'exécution.


            EndIf
            Local $iPIDP4B =  Run ("C:\Users\Julien\MyDeltaSyncBox\Projet\Delta\Play4Bridge\ffb-android\UwAmp.exe")

       EndIf


   If $StatusDHCP <> ProcessExists("tftpd64.exe") Then ; Vérifie si le processus est en cours d'exécution.
     If ProcessExists("tftpd64.exe") Then
       GUICtrlSetData($LabelTXTDHCP,"DHCP starting")
       $StatusDHCP =ProcessExists("tftpd64.exe");
       ; Draw PNG image
       $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($LabelDHCP))
       _GDIPlus_GraphicsDrawImage($hGraphic, $hHigh, 0, 0)

       GUICtrlSetState($idDHCP, $GUI_DISABLE)


     Else
       GUICtrlSetData($LabelTXTDHCP,"DHCP not starting")
       $StatusDHCP =ProcessExists("tftpd64.exe");
       ; Draw PNG image
       $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($LabelDHCP))
       _GDIPlus_GraphicsDrawImage($hGraphic, $hLow, 0, 0)

        GUICtrlSetState($idDHCP, $GUI_ENABLE)

     EndIf
   EndIf


   If $StatusP4B <> ProcessExists("UwAmp.exe") Then ; Vérifie si le processus est en cours d'exécution.
      If ProcessExists("UwAmp.exe") Then
          GUICtrlSetData($LabelTXTP4B,"P4B starting")
         $StatusP4B = ProcessExists("UwAmp.exe")
       ; Draw PNG image
       $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($LabelP4B))
       _GDIPlus_GraphicsDrawImage($hGraphic, $hHigh, 0, 0)

       GUICtrlSetState($idP4B, $GUI_DISABLE)

   Else
       GUICtrlSetData($LabelTXTP4B,"P4B not starting")
      $StatusP4B = ProcessExists("UwAmp.exe")
             ; Draw PNG image
       $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($LabelP4B))
       _GDIPlus_GraphicsDrawImage($hGraphic, $hLow, 0, 0)

       GUICtrlSetState($idP4B, $GUI_ENABLE)

   EndIf
 EndIf


 ; Recup Nom Carte Wifi
    Local $caption, $WLAN_CONNECTED
   Local $objWin = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Local $NetCards = $objWin.ExecQuery("Select * From Win32_NetworkAdapter where NetConnectionStatus=2")
    Local $NomCarteReso ="No Valid Card"
   Local $NomSSID = "NULL"
    For $objNetCard In $NetCards
        $NomCarteReso = $objNetCard.Caption ; Name; Description; ProductName
    Next

   ; Recup IP

   $ip = @IPAddress1
   If $ip = "0.0.0.0"  Or $ip = "127.0.0.1" Then
      $ip = "No Valid @ IP"

   ElseIf StringInStr($NomCarteReso, 'Wireless') = 0 Then
      $NomCarteReso ="Bad NetWork Card"

   Else

       Local $sOutput = Run("netsh wlan show int", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
       Local $sReturn = ""
       While 1
         $sReturn &= StdoutRead($sOutput)
         If @error Then Exitloop
       Wend

         $sSSID = StringRegExp($sReturn, '(?si) SSID\s* ÿ:\s(.*?)' & @CR,3)
         $NomSSID = $sSSID[0]
   EndIf

 if ($ip <> $ipcurrent) Then
   GUICtrlSetData ($LabelIP,$ip)
   $ipcurrent=$ip
 EndIf

 if ($NomSSID <> $NomSSIDCurrent) Then
   GUICtrlSetData ($LabelSsid,$NomSSID)
   $NomSSIDCurrent=$NomSSID
 EndIf

 if ($NomCarteReso <> $NomCarteResoCurrent) Then
   GUICtrlSetData ($LabelReso,$NomCarteReso)
   $NomCarteResoCurrent=$NomCarteReso
 EndIf



        $idMsg = GUIGetMsg()
    WEnd

EndFunc   ;==> P4B
 
JujuBois91
Niveau 1
Niveau 1
Messages : 11
Enregistré le : jeu. 15 juin 2017 10:08
Status : Hors ligne

Re: Besoin de correction

#2

Message par JujuBois91 »

Pouvez vous m'aider

Maintenant j ai une erreur juste en laissant tourner l'appli

(171) : ==> Subscript used on non-accessible variable.:
$NomSSID = $sSSID[0]
$NomSSID = $sSSID^ ERROR

Merci
Utilisateur 3309 supprimé
Status : Hors ligne

Re: Besoin de correction

#3

Message par Utilisateur 3309 supprimé »

Bonjour,
tu pourrais au moins décrire ce que fait ton script,et ce qui pose problème...

Concernant l'erreur : Subscript used on non-accessible variable.:
cette ligne n'a rien retourné:
$sSSID = StringRegExp($sReturn, '(?si) SSID\s* ÿ:\s(.*?)' & @CR,3)
donc $sSSID[0] n'existe pas.
avant de faire $NomSSID = $sSSID[0] il faut t'assurer que $sSSID est bien de venu un array.

If IsArray($sSSID) Then
$NomSSID = $sSSID[0]
else
$NomSSID = "ssid non trouvé"
endif
Avatar du membre
Yogui
Niveau 9
Niveau 9
Messages : 689
Enregistré le : ven. 18 avr. 2008 17:29
Status : Hors ligne

Re: Besoin de correction

#4

Message par Yogui »

Bonjour,

Je vais tenter de t'aider à avancer sachant que je ne peux pas vraiment executer ton code :

Tu commences par lancer une fonction, et tu met tout le code dedans--> une fonction

Tu utilises des exe mais ils ne sont pas dans le repertoire de ton script :

tu fais :
 Run ("C:\Users\Julien\MyDeltaSyncBox\Projet\Delta\Play4Bridge\tftpd64.460\tftpd64.exe")
je fait :
_lancementExeExterne("tftpd64.exe",@ScriptDir&"\sources")

Func _lancementExeExterne($ExeExt,$source)
   Local $testfichier= FileExists($source&"\"&$ExeExt)

    If $testfichier Then
        Run ($source&"\"&$ExeExt)
    Else
        msgBox("","","le fichier "&$ExeExt&" n'est pas présent dans le repertoire : "&$Source)
    EndIf
endfunc
L'idée est que si je dois lancer plusieurs exe j'utilise ma fonction qui va bien et je n'aurai pas besoin de la refaire

tu peux faire la même chose avec ce code :
        If $idMsg = $idDHCP Then
               If ProcessExists("tftpd64.exe") Then ; Vérifie si le processus Notepad est en cours d'exécution.

                           EndIf
                            Local $iPIDDHCP = Run ("C:\Users\Julien\MyDeltaSyncBox\Projet\Delta\Play4Bridge\tftpd64.460\tftpd64.exe")

                 EndIf
Je vais en faire une phrase :

Si $idMsg = $idDHCP Alors je vérifie si le processus tftpd64.exe est présent sur le poste et je ne fais rien...
et je lance tftpd64.exe (qui va donc être lancé deux fois ?)

il doit te manquer un truc du genre :
Si $idMsg = $idDHCP Alors je vérifie si le processus tftpd64.exe est présent sur le poste si oui je ferme ce processus puis je lance tftpd64.exe

Voilà un debut j'espère avoir été claire :)

Yogui
JujuBois91
Niveau 1
Niveau 1
Messages : 11
Enregistré le : jeu. 15 juin 2017 10:08
Status : Hors ligne

Re: [..]Besoin de correction

#5

Message par JujuBois91 »

Merci Beaucoup :)
Répondre