Wombat Posted January 21, 2014 Share Posted January 21, 2014 I need a different set of eyes on this, as I have ran through everything I can think of and cannot figure this thing out... Here's my script: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Users\Jniswonger\Workshop\Lab\test_res\SET_ico.ico #AutoIt3Wrapper_Outfile=UpdateTool.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIButton.au3> Global Const $SYSTEMDRIVE = EnvGet('systemdrive') Global $Srv = IniRead(@ScriptDir & "\Ctrl.ini", "server", "serverlocal", Default) Global $Current = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "versioninfo", "version", Default) Global $Available = IniRead($Srv & "Users$\Jniswonger\SET\Ctrl.ini", "versioninfo", "version", Default) Global $Origin = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "update", "SETborn", Default) Global $sSourceFolder = $Srv & "Users$\Jniswonger\SET\" Global $sDestFolder = $SYSTEMDRIVE & "\SET\" Opt("GUICloseOnEsc", 1) Opt("GUIOnEventMode", 1) If ProcessExists("SET.exe") Then ProcessClose("SET.exe") Sleep(1000) EndIf #region GUI $mGUI = GUICreate("Update Tool", 422, 303, Default, Default, BitOR($WS_THICKFRAME, $WS_POPUP)) GUISetOnEvent($GUI_EVENT_CLOSE, "MainGUIClose") $Label1 = GUICtrlCreateLabel("SET Update Tool", 139, 16, 142, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Versions = GUICtrlCreateGroup("Version", 32, 48, 361, 105, BitOR($GUI_SS_DEFAULT_GROUP, $BS_RIGHT)) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Current: " & $Current, 48, 80) $Label3 = GUICtrlCreateLabel("Available: " & $Available, 48, 112) $LabelCurrent = GUICtrlCreateLabel("You have the most up-to-date version of SET", 90, 80, 400, 55) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlCreateGroup("", -99, -99, 1, 1) $Button1 = GUICtrlCreateButton("Update", 135, 200, 149, 43) GUICtrlSetCursor(-1, 0) GUICtrlSetOnEvent(-1, "_update") FadeGUI_in() #endregion GUI If $Current == $Available Then _UpIsCrnt() EndIf If $Origin = "true" Then FileRecycle($SYSTEMDRIVE & "\SET") Sleep(1000) _update() EndIf While 1 Sleep(100) WEnd Func MainGUIClose() GUIDelete("Update Tool") Sleep(10) Exit EndFunc ;==>MainGUIClose Func _update() If FileExists($Srv & "Users$\Jniswonger\SET\SET.exe") Then _CopyFolder($sSourceFolder, $sDestFolder) If @error Then MsgBox(0, "Error - File Not Found", "Could not find the update, contact your administrator to resolve this issue") EndIf Else MsgBox(0, "Error - File Not Found", "Could not find the update, contact your administrator to resolve this issue") EndIf Sleep(2500) If $Origin = "true" Then IniWrite($SYSTEMDRIVE & "\SET\Ctrl.ini", "update", "SETborn", "false") Sleep(100) _UpIsCrnt() Sleep(650) ShellExecute($SYSTEMDRIVE & "\SET\SET.exe") Sleep(100) ProcessClose("UpdateTool.exe") Else _Reset() EndIf EndFunc ;==>_update Func _CopyFolder($sSourceFolder, $sDestFolder) Local $au3=_GetAppropriatePath("C:\Program*\AutoIt3*\autoit3.exe*", 0) DirRemove($sDestFolder, 1) Local $iSourceSize = DirGetSize($sSourceFolder), $iDestSize Local $pid = Run($au3 & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Updating Software", "Please wait" & Chr(44) & " the latest version of your software is being retrieved" & Chr(46)) Do $iDestSize = DirGetSize($sDestFolder) Local $ipct = Int(($iDestSize / $iSourceSize) * 100) ProgressSet($ipct, $ipct & '%') Sleep(2000) Until Not ProcessExists($pid) ProgressSet(100, "Done", "Complete") Sleep(1000) ProgressOff() If Not FileExists(@DesktopDir & "\SET Shortcut") Then FileCreateShortcut($SYSTEMDRIVE & "\SET\SET.exe", @DesktopDir & "\SET Shortcut") EndFunc ;==>_CopyFolder Func _UpIsCrnt() GUICtrlDelete($Label3) GUICtrlDelete($Label2) GUICtrlSetState($LabelCurrent, $GUI_SHOW) GUICtrlSetCursor($Button1, 7) EndFunc ;==>_UpIsCrnt Func _Reset();Exits, then runs the script again, thus resetting it FadeGUI_out() If @Compiled Then Run(FileGetShortName(@ScriptFullPath)) Else Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc ;==>_Reset Func FadeGUI_out();Uses a DLL call to fade the $mGUI Tool out DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $mGUI, "int", 1500, "long", 0x90000) GUISetState(@SW_HIDE, "Update Tool") Sleep(10) EndFunc ;==>FadeGUI_out Func FadeGUI_in();Uses a DLL call to fade the $mGUI Tool in GUISetState(@SW_SHOW, "Update Tool") DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $mGUI, "int", 1500, "long", 0x80000) Sleep(10) EndFunc ;==>FadeGUI_in Func _GetAppropriatePath($sPath, $iLevel = 0) Local $hSearch, $tPath, $File, $Item, $Path, $Ret, $Dir = '', $Suf = '', $Result = '' $tPath = DllStructCreate('wchar[1024]') $Ret = DllCall('kernel32.dll', 'dword', 'GetFullPathNameW', 'wstr', $sPath, 'dword', 1024, 'ptr', DllStructGetPtr($tPath), 'ptr', 0) If (@error) Or (Not $Ret[0]) Then Return '' EndIf $sPath = DllStructGetData($tPath, 1) If StringRight($sPath, 1) = '\' Then $Dir = '\' EndIf $Item = StringSplit(StringRegExpReplace($sPath, '\\\Z', ''), '\') Select Case $iLevel + 1 = $Item[0] If FileExists($sPath) Then Return $sPath Else Return '' EndIf Case $iLevel + 1 > $Item[0] Return '' EndSelect For $i = 1 To $iLevel + 1 $Result &= $Item[$i] & '\' Next $Result = StringRegExpReplace($Result, '\\\Z', '') If Not FileExists($Result) Then Return '' EndIf $hSearch = FileFindFirstFile($Result & '\*') If $hSearch = -1 Then Return '' EndIf For $i = $iLevel + 3 To $Item[0] $Suf &= '\' & $Item[$i] Next While 1 $File = FileFindNextFile($hSearch) If @error Then $Result = '' ExitLoop EndIf If (Not @extended) And ($Dir) And ($iLevel + 2 = $Item[0]) Then ContinueLoop EndIf $Ret = DllCall('shlwapi.dll', 'int', 'PathMatchSpecW', 'wstr', $File, 'wstr', $Item[$iLevel + 2]) If (Not @error) And ($Ret[0]) Then $Path = _GetAppropriatePath($Result & '\' & $File & $Suf & $Dir, $iLevel + 1) If $Path Then $Result = $Path ExitLoop EndIf EndIf WEnd FileClose($hSearch) Return $Result EndFunc ;==>_GetAppropriatePath I've checked all my variables and they are correct.... I haven't changed the way the code works, only updated the variable values in the ini file. This was working a week ago and now it's not. I was thinkin it could be server related so i tried on many different pc's.... On a number of them XP/Win7 it works.... on another group of them it does not Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
BrewManNH Posted January 21, 2014 Share Posted January 21, 2014 Not a whole lot of information to go on from you. You say it doesn't work for some computers, what doesn't work and where does it stop working? Have you done any error checking, checking the values/contents of variables as the script progresses, checked what's different on the computers that this doesn't work on from the ones that it does work on, checked if the users having issues have different permissions than others? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Wombat Posted January 21, 2014 Author Share Posted January 21, 2014 (edited) I've ran it from my system and it works logged on as merunning on a system that's failing logged on as me it still fails.So from there I considered it not to be a permission error. What happens is the program runs and checks if the value in the version on the system is equal to the value of the version on the server. If it's different it runs the "update tool" directly from the server.In both cases fail or succeed, the "update tool" runs and successfully identifies file versions, it closes the previous program and begins copying the file, it says the copying fucntion is completed but when it attempts to run the program windows throws up an error that it cannot find the specified file the "update tool" is trying to run. I go check and indeed it did not copy the file over. It's mind boggling because it works on some systems and not on others but I'm using my user credentials on all of them. also, the systems are XP/Win7 some work some do not EDIT: I'm pretty sure the error lies here:Func _CopyFolder($sSourceFolder, $sDestFolder) Local $au3=_GetAppropriatePath("C:\Program*\AutoIt3*\autoit3.exe*", 0) DirRemove($sDestFolder, 1) Local $iSourceSize = DirGetSize($sSourceFolder), $iDestSize Local $pid = Run($au3 & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Updating Software", "Please wait" & Chr(44) & " the latest version of your software is being retrieved" & Chr(46)) Do $iDestSize = DirGetSize($sDestFolder) Local $ipct = Int(($iDestSize / $iSourceSize) * 100) ProgressSet($ipct, $ipct & '%') Sleep(2000) Until Not ProcessExists($pid) ProgressSet(100, "Done", "Complete") Sleep(1000) ProgressOff() If Not FileExists(@DesktopDir & "\SET Shortcut") Then FileCreateShortcut($SYSTEMDRIVE & "\SET\SET.exe", @DesktopDir & "\SET Shortcut") EndFunc ;==>_CopyFolder Edited January 21, 2014 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
MHz Posted January 22, 2014 Share Posted January 22, 2014 OnEvent function _update() calls _CopyFolder and then checks @error. I see no SetError() used in _CopyFolder(). Many issues exist with error checking like $au3 used in _CopyFolder is not checked if contains a value from _GetAppropiatePath() and SetError() is not used in the latter function to check for error. I could go on but to sum it up, your error checking is hit and miss. My advice is to add the missing error checking code in so the script will alert on issues. As for _CopyFolder(), I see you are already using @AutoItExe in your script so I see no reason not to use it in that UDF. So the change would be this. Func _CopyFolder($sSourceFolder, $sDestFolder) ;Local $au3=_GetAppropriatePath("C:\Program*\AutoIt3*\autoit3.exe*", 0) DirRemove($sDestFolder, 1) Local $iSourceSize = DirGetSize($sSourceFolder), $iDestSize Local $pid = Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Updating Software", "Please wait" & Chr(44) & " the latest version of your software is being retrieved" & Chr(46)) Do $iDestSize = DirGetSize($sDestFolder) Local $ipct = Int(($iDestSize / $iSourceSize) * 100) ProgressSet($ipct, $ipct & '%') Sleep(2000) Until Not ProcessExists($pid) ProgressSet(100, "Done", "Complete") Sleep(1000) ProgressOff() If Not FileExists(@DesktopDir & "\SET Shortcut") Then FileCreateShortcut($SYSTEMDRIVE & "\SET\SET.exe", @DesktopDir & "\SET Shortcut") EndFunc ;==>_CopyFolder That may help to eliminate 1 possible issue. _GetAppropriatePath() has been commented as unneeded. Next you have DirRemove() with flag 1. If that fails then your Run() function is not going to do well as the DirCopy() has no overwrite flag used so that could become a mix up of files let alone a file in use in that folder causing issues. The rest of the code in that UDF is reasonable so I will not touch on it. Link to comment Share on other sites More sharing options...
Wombat Posted January 22, 2014 Author Share Posted January 22, 2014 (edited) OnEvent function _update() calls _CopyFolder and then checks @error. I see no SetError() used in _CopyFolder(). Many issues exist with error checking like $au3 used in _CopyFolder is not checked if contains a value from _GetAppropiatePath() and SetError() is not used in the latter function to check for error. I could go on but to sum it up, your error checking is hit and miss. My advice is to add the missing error checking code in so the script will alert on issues. As for _CopyFolder(), I see you are already using @AutoItExe in your script so I see no reason not to use it in that UDF. So the change would be this. Func _CopyFolder($sSourceFolder, $sDestFolder) ;Local $au3=_GetAppropriatePath("C:\Program*\AutoIt3*\autoit3.exe*", 0) DirRemove($sDestFolder, 1) Local $iSourceSize = DirGetSize($sSourceFolder), $iDestSize Local $pid = Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Updating Software", "Please wait" & Chr(44) & " the latest version of your software is being retrieved" & Chr(46)) Do $iDestSize = DirGetSize($sDestFolder) Local $ipct = Int(($iDestSize / $iSourceSize) * 100) ProgressSet($ipct, $ipct & '%') Sleep(2000) Until Not ProcessExists($pid) ProgressSet(100, "Done", "Complete") Sleep(1000) ProgressOff() If Not FileExists(@DesktopDir & "\SET Shortcut") Then FileCreateShortcut($SYSTEMDRIVE & "\SET\SET.exe", @DesktopDir & "\SET Shortcut") EndFunc ;==>_CopyFolder That may help to eliminate 1 possible issue. _GetAppropriatePath() has been commented as unneeded. Next you have DirRemove() with flag 1. If that fails then your Run() function is not going to do well as the DirCopy() has no overwrite flag used so that could become a mix up of files let alone a file in use in that folder causing issues. The rest of the code in that UDF is reasonable so I will not touch on it. I would go with that except one tiny detail, which i'm at fault for not providing the info forand i apologize. This line: Local $pid = Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') Will error out every time because the Macro @AutoItExe will look at the incorrect drive. The user is on a domain and the users corresponding drive on the domain is P: so the Macro actually looks on said P: drive for the AutoIt exe file instead of that machines physical harddrive (C:)... which is why i was using the Local $au3=_GetAppropriatePath("C:\Program*\AutoIt3*\autoit3.exe*", 0) to call the local install of AutoIt I believe I may need to rewrite how the _CopyFolder() function works.... quick question, common sense is hinting me at the answer, but this: Local $pid = Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') wouldn't work if AutoIt is not installed on the machine running this command??? would it? Edited January 22, 2014 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
BrewManNH Posted January 22, 2014 Share Posted January 22, 2014 If the script is compiled, it will use the script as the full path and file name, if not compiled it will use the full path of wherever the AutoIt3.exe (or_x64.exe) is located on their system. @AutoItExe The full path and filename of the AutoIt executable currently running. For compiled scripts it is the path of the compiled script. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
MHz Posted January 22, 2014 Share Posted January 22, 2014 On the latest AutoIt version, you may need to use a pragma compile directive to use a compiled script as an interpreter while 3.3.8.1 and earlier could execute a script by default. Example, this code will restart the script whether as au3 or compiled as exe. Run it without parameters. #pragma compile(AutoItExecuteAllowed, True) If Not $CMDLINE[0] Then Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') ElseIf $CMDLINE[1] = '/restart' Then MsgBox(0, @ScriptName, 'Restarted'); expect to see this Else MsgBox(0x30, @ScriptName, 'Test failed') EndIf So that means that you could even change the _Reset function to be like this Func _Reset();Exits, then runs the script again, thus resetting it FadeGUI_out() Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '"') Exit EndFunc ;==>_Reset Again note that latest version requires the pragma compile directive to work for the compiled script. Sorry, should have mentioned the pragma compile directive prior as I did not consider it as it is a rather new addition to use that was not needed before. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now