Jump to content
WJAMET

[Solved] My autoit script not work in some computer

Recommended Posts

Hello,

I have created a script on my own computer for my Raspberry.

It work on my computer. But not on another.

#Region INCLUDE
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Process.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <CSVSplit.au3>
#include <Array.au3>
#EndRegion INCLUDE
#Region GUI
$Form = GUICreate("Rpi-Utility", 437, 315, 2415, 365)
GUISetBkColor(0xE3E3E3)
$Group1 = GUICtrlCreateGroup("Choix n°01 :", 8, 8, 417, 105)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Group1), "wstr", 0, "wstr", 0)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
$Radio_Reboot = GUICtrlCreateRadio("Reboot", 16, 48, 113, 17)
GUICtrlSetState($Radio_Reboot, $GUI_CHECKED)
GUICtrlSetColor(-1, 0x000000)
$Radio_Shutdown = GUICtrlCreateRadio("Shutdown", 16, 72, 113, 17)
$Radio_USB = GUICtrlCreateRadio("USB", 136, 48, 113, 17)
$Radio_Network = GUICtrlCreateRadio("Network", 136, 72, 113, 17)
$Radio_Chromium = GUICtrlCreateRadio("Chromium", 256, 48, 113, 17)
$Radio_cache = GUICtrlCreateRadio("Cache", 256, 72, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Choix n°02 :", 8, 120, 417, 153)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Group2), "wstr", 0, "wstr", 0)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
$Label1 = GUICtrlCreateLabel("Raspberry", 16, 152, 86, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label2 = GUICtrlCreateLabel("Pointer clique avec CTRL", 16, 176, 126, 17)
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label3 = GUICtrlCreateLabel("pour multi-sélectionner.", 16, 192, 112, 17)
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$List = GUICtrlCreateListView("", 248, 144, 161, 106,$LVS_REPORT) ; multi selection
;~ $List = GUICtrlCreateListView("", 248, 144, 161, 106,$LVS_SINGLESEL) ; mono-selection
GUICtrlSetData(-1, "")
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Label4 = GUICtrlCreateLabel("v1.2.0", 400, 296, 34, 17)
$Button_OK = GUICtrlCreateButton("OK", 145, 280, 75, 25)
$Button_Close = GUICtrlCreateButton("Fermer", 235, 280, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region ; CSV to Array to List
Local $aArray
;~ _FileReadToArray ("C:\Apax\Outils\RPI-Utility\IP.csv", $aArray, $FRTA_COUNT, ",") ; Prod
_FileReadToArray (@ScriptDir & "\IP.csv", $aArray, $FRTA_NOCOUNT, ",") ; Test
_GUICtrlListView_AddColumn($List,"IP", 92)
_GUICtrlListView_AddColumn($List,"Tirage", 64)

; Add data
_GUICtrlListView_AddArray($List, $aArray)
#EndRegion ; CSV to Array to List

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

         $iIndex = _GUICtrlListView_GetItemTextArray($List,0)
         $Number=_GUICtrlListView_GetItemCount($List)-1

         If GUICtrlRead($Radio_Reboot) = 1 Then
            Name ("sudo reboot -h now","Reboot")
         ElseIf GUICtrlRead($Radio_Shutdown) = 1 Then
            Name ("sudo shutdown -h now","Shutdown")
         ElseIf GUICtrlRead($Radio_USB) = 1 Then
            Name ("./restart_pyserial","USB")
         ElseIf GUICtrlRead($Radio_Network) = 1 Then
            Name ("./restart_network.sh","Network")
         ElseIf GUICtrlRead($Radio_Chromium) = 1 Then
            Name ("./restart_chromium.sh","Chromium")
         ElseIf GUICtrlRead($Radio_Cache) = 1 Then
            Name ("./remove_cache","Cache")
         EndIf
      Case $Button_Close
      Exit
   EndSwitch
WEnd

Func Name($Command,$Action)
   For $i=0 to $Number
      If _GUICtrlListView_GetItemSelected($List,$i) Then
         $IP = $aArray[$i][0]
         Run(@ComSpec & " /c " & 'echo y | '&@WorkingDir&'\plink.exe -ssh -l pi -pw pijdc '&$IP&' '&$Command, "", @SW_MINIMIZE)
         FileWriteLine(@WorkingDir&"\log.txt",_NowDate( )&" "&_NowTime(5)&" "&$IP&" "&$Action)
         Sleep (1000)
      EndIf
   Next
EndFunc

With or without the RequireAdmin doesn't make a difference.

Could someone help me to understand why my script works great on my own computer, but when you move it to another computer it doesn't work?

Share this post


Link to post
Share on other sites

Does it throw any errors? Does it display anything? How isn't working?

Does the other computer have plink.exe in the directory you expect it to be?

Share this post


Link to post
Share on other sites
  • Does it throw any errors? Does it display anything? How isn't working?

Work perfectly on my own computer (no errors).

And with another computer,  my software is launched but nothing appear on the screen.

image.png.a4cffef6447adf97de6ef6a075b238a9.png

  • Does the other computer have plink.exe in the directory you expect it to be?

Yes.

Share this post


Link to post
Share on other sites

If you can get autoIt on this computer, you may try running the script instead of the exe to see what's printed to the console.

Also, you can add If statements after the lines you think they may throw an error, like a

If @error then MsgBox(0,"DLL Call Error","Error: " & @error)

after every DLLCall() for example.

 

Or maybe try it without using the UxTheme.dll (If I understood correctly after my googling, it changes the theme of the specified window)

Share this post


Link to post
Share on other sites

Add in error handling and logging to find out what's not working as you expect.

You should also wrap your run commands with double quotes in case your @workingdir contains spaces.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

... So, everything is ok with my computer. And just for a test, I installed AutoIt on another computer and when I launched the script with it the GUI doesn't appear.

With Opt("TrayIconDebug",1) i can see me enter into the Switch but nothing after.

PS: Sorry for my English.

Share this post


Link to post
Share on other sites

$Form = GUICreate("Rpi-Utility", 437, 315, 2415, 365)
isnt your window outside the field of view on the other computer?
maybe you can try

$Form = GUICreate("Rpi-Utility", 437, 315, -1,-1)

Share this post


Link to post
Share on other sites
Posted (edited)

@jvds

Your are my new god with ottogod.

 

Thanks you everybody for your help.

Edited by WJAMET
french => english

Share this post


Link to post
Share on other sites
Posted (edited)

Corrected version :

#Region INCLUDE
#include <Array.au3> ;
;~ #include <ButtonConstants.au3>
#include <ColorConstantS.au3> ;
#include <CSVSplit.au3> ;
#include <File.au3> ;
;~ #include <FileConstants.au3>
#include <FontConstants.au3> ;
#include <GUIConstantsEx.au3> ;
;~ #include <GUIListBox.au3>
#include <GUIListView.au3>
#include <MsgBoxConstants.au3> ;
;~ #include <Process.au3>
;~ #include <StaticConstants.au3>
#include <WindowsConstants.au3>
#EndRegion INCLUDE
#Region GUI
$Form = GUICreate("Rpi-Utility", 437, 315, -1, -1)
   GUISetBkColor(0xE3E3E3)
$Group_01 = GUICtrlCreateGroup("Choix n°01 :", 8, 8, 417, 105)
   DllCall("UxTheme.dll", "int64", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Group_01), "wstr", 0, "wstr", 0)
   GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
   GUICtrlSetColor(-1, 0xFFFFFF)
   GUICtrlSetBkColor(-1, 0x000000)
$Radio_Reboot = GUICtrlCreateRadio("Reboot", 16, 48, 113, 17)
   GUICtrlSetState($Radio_Reboot, $GUI_CHECKED)
   GUICtrlSetColor(-1, 0x000000)
$Radio_Shutdown = GUICtrlCreateRadio("Shutdown", 16, 72, 113, 17)
$Radio_USB = GUICtrlCreateRadio("USB", 136, 48, 113, 17)
$Radio_Network = GUICtrlCreateRadio("Network", 136, 72, 113, 17)
$Radio_Chromium = GUICtrlCreateRadio("Chromium", 256, 48, 113, 17)
$Radio_cache = GUICtrlCreateRadio("Cache", 256, 72, 113, 17)
   GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group_02 = GUICtrlCreateGroup("Choix n°02 :", 8, 120, 417, 153)
   DllCall("UxTheme.dll", "int64", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Group_02), "wstr", 0, "wstr", 0)
   GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
   GUICtrlSetColor(-1, 0xFFFFFF)
   GUICtrlSetBkColor(-1, 0x000000)
$Label1 = GUICtrlCreateLabel("Raspberry", 16, 152, 86, 24)
   GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
   GUICtrlSetColor(-1, 0x000000)
   GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label2 = GUICtrlCreateLabel("Pointer clique avec CTRL", 16, 176, 126, 17)
   GUICtrlSetColor(-1, 0x808080)
   GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label3 = GUICtrlCreateLabel("pour multi-sélectionner.", 16, 192, 112, 17)
   GUICtrlSetColor(-1, 0x808080)
   GUICtrlSetBkColor(-1, 0xE3E3E3)
$List = GUICtrlCreateListView("", 248, 144, 161, 106,$LVS_REPORT) ; multi selection
   GUICtrlSetData(-1, "")
   GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label_Version = GUICtrlCreateLabel("v1.2.0", 400, 296, 34, 17)
$Button_OK = GUICtrlCreateButton("OK", 145, 280, 75, 25)
$Button_Close = GUICtrlCreateButton("Fermer", 235, 280, 75, 25)
GUISetState(@SW_SHOW,$Form)
#EndRegion
#Region ; CSV to Array to List
Local $aArray
_FileReadToArray (@WorkingDir & "\IP.csv", $aArray, $FRTA_NOCOUNT, ",")
_GUICtrlListView_AddColumn($List,"IP", 92)
_GUICtrlListView_AddColumn($List,"Tirage", 64)
_GUICtrlListView_AddArray($List, $aArray)
#EndRegion ; CSV to Array to List
While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button_OK
         $iIndex = _GUICtrlListView_GetItemTextArray($List,0)
         $Number=_GUICtrlListView_GetItemCount($List)-1
         If GUICtrlRead($Radio_Reboot) = $GUI_CHECKED Then
            Name ("sudo reboot -h now","Reboot")
         ElseIf GUICtrlRead($Radio_Shutdown) = $GUI_CHECKED Then
            Name ("sudo shutdown -h now","Shutdown")
         ElseIf GUICtrlRead($Radio_USB) = $GUI_CHECKED Then
            Name ("./restart_pyserial","USB")
         ElseIf GUICtrlRead($Radio_Network) = $GUI_CHECKED Then
            Name ("./restart_network.sh","Network")
         ElseIf GUICtrlRead($Radio_Chromium) = $GUI_CHECKED Then
            Name ("./restart_chromium.sh","Chromium")
         ElseIf GUICtrlRead($Radio_Cache) = $GUI_CHECKED Then
            Name ("./remove_cache.sh","Cache")
         EndIf
      Case $Button_Close
         Exit
   EndSwitch
WEnd

Func Name($Command,$Action)
   For $i=0 to $Number
      If _GUICtrlListView_GetItemSelected($List,$i) Then
         $IP = $aArray[$i][0]
         Run(@ComSpec & " /c " & 'echo y | '&@WorkingDir&'\plink.exe -ssh -l pi -pw pijdc '&$IP&' '&$Command, "", @SW_MINIMIZE)
         _FileWriteLog(@WorkingDir&"\log.txt",$IP&" "&$Action)
         Sleep (1000)
      EndIf
   Next
EndFunc

 

Edited by WJAMET

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...