Valuater Posted October 12, 2010 Share Posted October 12, 2010 (edited) I have benn at this for a while, I have made an example script as short as I could. This will run on the desktop only, when I try to put it in C drive it erros with "Object referenced outside of a 'with' statement" I have tried multiple things and have probably missed the easy one right in front of my tored eyes. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** MsgBox(0, @error, CCleaner()) Exit Func CCleaner() $CC_File = @ScriptDir & "\PCCleaner\CCleaner.exe" If Not FileExists(@ScriptDir & "\CCleaner.zip") Then $cntloop = 0 While 1 If Ping("www.Autoit3.com", 4000) > 0 Then ExitLoop If MsgBox(262149, "Connection Error", "An Internet Connection is Required to download Cleaning Engine. ", 10) = 2 Then $cntloop += 1 If $cntloop >= 3 Then Return SetError(-1, -1, "Internet Connection Error") EndIf EndIf WEnd $success = InetGet("http://www.piriform.com/ccleaner/download/portable/downloadfile", "CCleaner.zip") If $success = 0 Then Return -1 EndIf If FileExists(@ScriptDir & "\CCleaner.zip") And Not FileExists($CC_File) Then $ret = _Zip_Unzip(@ScriptDir & "\CCleaner.zip", "CCleaner.exe", @ScriptDir & "\PCCleaner", 0) If @error Then $Ztest = _Zip_DllChk() Return SetError(-1, @error, "UnZip Error = " & $ret & @CRLF & "Dll Check Error = " & $Ztest & @CRLF) EndIf Sleep(1000) $ret2 = _Zip_Unzip(@ScriptDir & "\CCleaner.zip", "unicows.dll", @ScriptDir & "\PCCleaner", 0) If @error Then $Ztest2 = _Zip_DllChk() Return SetError(-1, @error, "UnZip Error = " & $ret2 & @CRLF & "Dll Check Error = " & $Ztest2 & @CRLF) EndIf Sleep(1000) ElseIf FileExists($CC_File) Then ; do nothing Else Return SetError(-1, -1, "CC Install error") EndIf $staus = RunWait($CC_File & " /AUTO", "", @SW_HIDE) If $staus = 0 Then SetError(-1, -1, "Error at the Run statement") Return SetError(0, 0, "All is Good!!") EndFunc ;==>CCleaner ; Function Name: _Zip_Unzip() ; Author(s): torels_ Func _Zip_Unzip($hZipFile, $hFilename, $hDestPath, $flag = 1) Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, -1, "No Zip Dll");no dll If Not _IsFullPath($hZipFile) Then Return SetError(4, -1, "Zip File is not a full path ") ;zip file isn't a full path If Not FileExists($hZipFile) Then Return SetError(2, -1, "No zip file found ") ;no zip file If Not FileExists($hDestPath) Then DirCreate($hDestPath) $oApp = ObjCreate("Shell.Application") $hFolderitem = $oApp.NameSpace($hZipFile).Parsename($hFilename) $oApp.NameSpace($hDestPath).Copyhere($hFolderitem) While 1 If $flag = 1 Then _Hide() If FileExists($hDestPath & "\" & $hFilename) Then Return SetError(0, 0, 1) ExitLoop EndIf Sleep(500) WEnd EndFunc ;==>_Zip_Unzip ; Function Name: _Zip_DllChk() ; Author(s): smashley Func _Zip_DllChk() If Not FileExists(@SystemDir & "\zipfldr.dll") Then Return SetError(2, "File Not Found: " & @SystemDir & "\zipfldr.dll", -1) If Not RegRead("HKEY_CLASSES_ROOT\CLSID\{E88DCCE0-B7B3-11d1-A9F0-00AA0060FA31}", "") Then Return SetError(3, "RegKey Not Found: HKEY_CLASSES_ROOT\CLSID\{E88DCCE0-B7B3-11d1-A9F0-00AA0060FA31}", -1) Return SetError(0, 0, " All required files were found. ") EndFunc ;==>_Zip_DllChk ; Function Name: _IsFullPath() ; Author(s): torels_ Func _IsFullPath($path) If StringInStr($path, ":\") Then Return True Else Return False EndIf EndFunc ;==>_IsFullPath ; Author(s): torels_ ; Interior Function Func _Hide() If ControlGetHandle("[CLASS:#32770]", "", "[CLASS:SysAnimate32; INSTANCE:1]") <> "" And WinGetState("[CLASS:#32770]") <> @SW_HIDE Then ;The Window Exists $hWnd = WinGetHandle("[CLASS:#32770]") WinSetState($hWnd, "", @SW_HIDE) EndIf EndFunc ;==>_Hide ; _ArrayAdd ; Author Jos van der Zande <jdeb at autoitscript dot com> Func _ArrayAdd(ByRef $avArray, $vValue) If Not IsArray($avArray) Then Return SetError(1, 0, -1) If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, -1) Local $iUBound = UBound($avArray) ReDim $avArray[$iUBound + 1] $avArray[$iUBound] = $vValue Return $iUBound EndFunc ;==>_ArrayAdd thx Valuater 8) PS I have been testing when compiled... Edited October 12, 2010 by Valuater Link to comment Share on other sites More sharing options...
BrewManNH Posted October 12, 2010 Share Posted October 12, 2010 I noticed that when it calls the function _Zip_Unzip with the script in the C:\ root that $hZipFile = C:\\CCleaner.zip. When it's called from any other folder, other that a drive's root folder, it only has one "\" prior to the file name. Perhaps that is throwing the program off, and you might want to check to see if it's being run from the root of a drive and not put the "\" before the file name in those cases. 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...
Valuater Posted October 12, 2010 Author Share Posted October 12, 2010 I noticed that when it calls the function _Zip_Unzip with the script in the C:\ root that $hZipFile = C:\\CCleaner.zip. When it's called from any other folder, other that a drive's root folder, it only has one "\" prior to the file name. Perhaps that is throwing the program off, and you might want to check to see if it's being run from the root of a drive and not put the "\" before the file name in those cases.Thanks BrewMan, I was actually thinking the same thing, when I was supposed to be sleeping last night. Seems at times when I am truly frustrated with a script, I get clarity when I toss and turn. Not good for the next day though.I actually came back here to post that I was using it in the root drive... and my computer and Autoit ver info.I think you got the answer, and I appreciated your time.. Thx againValuater8)PS... this may be something for the dev's to take a look at too.... 8) Link to comment Share on other sites More sharing options...
trancexx Posted October 12, 2010 Share Posted October 12, 2010 (edited) Don't use torels_'s zip functions. wraithdu solved many problems that UDF had with his UDF, even if maybe not this one. edit: Valuater... Valuater, that sounds familiar. Hmm. You were here before, right? Edited October 12, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
UEZ Posted October 12, 2010 Share Posted October 12, 2010 (edited) I had the same problem and the problem is to check when exactly the Zip thread has finished the job. I tried to solve it that way a long time ago (didn't do any update until now) and maybe the new revised Zip UDF from Wraithdu will do it more elegant. expandcollapse popup#include <WinAPi.au3> #include <Array.au3> Opt('MustDeclareVars', 1) HotKeySet("{ESC}", "_Exit") Global Const $TH32CS_SNAPTHREAD = 0x00000004 Global Const $THREADENTRY32 = "dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;" Global $zip_file = "c:\Test.zip" Global $source_folder = @WindowsDir & "\Inf\" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Add_Folder_2_ZIP($source_folder, $zip_file) Func Add_Folder_2_ZIP($folder, $zip_filename, $flag = 4) Local $hZIP, $ZIP_fileheader, $obj_ZIP, $obj_Folder, $obj_ZIP_Folder, $obj_Copy, $files, $cf Local $arr, $arr1, $arr2 $hZIP = FileOpen($zip_filename, 26) $ZIP_fileheader = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) FileWrite($hZIP, $ZIP_fileheader) FileClose($hZIP) $arr1 = _GetAllProcessThreads(@AutoItPID) $obj_ZIP = ObjCreate("Shell.Application") $obj_Folder = $obj_ZIP.NameSpace($folder) $obj_ZIP_Folder = $obj_ZIP.NameSpace($zip_filename) $obj_Copy = $obj_ZIP.NameSpace($zip_filename).CopyHere($obj_Folder.Items, $flag) ;add files to ZIP archive $files = $obj_ZIP.NameSpace($folder).Items.Count $cf = $obj_ZIP.NameSpace($zip_filename).Items.Count While $cf < $files $cf = $obj_ZIP.NameSpace($zip_filename).Items.Count ;~ ConsoleWrite($cf & "/" & $files & @CRLF) Sleep(1000) $arr2 = _GetAllProcessThreads(@AutoItPID) $arr = _ArrayDiff($arr2, $arr1) If $arr[0] = 0 Then ExitLoop WEnd EndFunc ;==>Add_Folder_2_ZIP Func _ErrFunc() ConsoleWrite("error" & @CRLF) Return EndFunc ; ------------------------------------------------- ; Function: _ArrayDiff ; Purpose: Returns an array of elements from $avArray1 that do not occur in $avArray2 ; Syntax: _ArrayDiff(ByRef $avArray1, ByRef $avArray2 [, $f_CaseSense = 0]) ; Where: $avArray1 = ByRef source array ; $avArray2 = ByRef array to search for $avArray1 elements ; $f_CaseSense (optional) = Case sensitivity as passed to StringInStr() ; 0 = not case sensitive, using the user's locale (default) ; 1 = case sensitive ; 2 = not case sensitive, using a basic/faster comparison ; Returns: On success returns an array with [0] = count containing any elements ; from $avArray1 that do not occur in $avArray2 ; If all elements in $avArray1 occur in $avArray2 then [0] = 0 ; On Failure returns 1-element array [0] = 0 and sets @error. ; Author: PsaltyDS on www.autoitscript.com/forum ; Notes: Similar to PHP array_diff function ; -------------------------------------------------- Func _ArrayDiff(ByRef $avArray1, ByRef $avArray2, $f_CaseSense = 0) Local $avRET[1] = [0], $sRET = "" If (IsArray($avArray1) = 0) Or (UBound($avArray1, 0) <> 1) Then Return SetError(1, 1, $avRET) If (IsArray($avArray2) = 0) Or (UBound($avArray2, 0) <> 1) Then Return SetError(1, 2, $avRET) Local $sArray2 = Chr(1) & _ArrayToString($avArray2, Chr(1)) & Chr(1) For $n = 0 To UBound($avArray1) - 1 If Not StringInStr($sArray2, Chr(1) & $avArray1[$n] & Chr(1)) Then $sRET &= $avArray1[$n] & Chr(1) Next If StringLen($sRET) Then $sRET = StringTrimRight($sRET, 1) $avRET = StringSplit($sRET, Chr(1)) EndIf Return $avRET EndFunc ;==>_ArrayDiff Func _GetAllProcessThreads($iPid) ; thanks to monoceres Local $call = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0) Local $handle = $call[0] Local $RetArr[1] Local $te32 = DllStructCreate($THREADENTRY32) DllStructSetData($te32, "dwSize", DllStructGetSize($te32)) $call = DllCall("Kernel32.dll", "int", "Thread32First", "ptr", $handle, "ptr", DllStructGetPtr($te32)) If DllStructGetData($te32, "th32OwnerProcessID") = $iPid Then _GetAllThreads_ArrHelper($RetArr, $te32) Do $call = DllCall("Kernel32.dll", "int", "Thread32Next", "ptr", $handle, "ptr", DllStructGetPtr($te32)) If Not $call[0] Then ExitLoop If DllStructGetData($te32, "th32OwnerProcessID") = $iPid Then _GetAllThreads_ArrHelper($RetArr, $te32) Until True And False _ArrayDelete($RetArr, 0) _WinAPI_CloseHandle($handle) Return $RetArr EndFunc ;==>_GetAllProcessThreads Func _GetAllThreads_ArrHelper(ByRef $arr, $TE32_Struct) ; thanks to monoceres Local $ub = UBound($arr) ReDim $arr[$ub + 1] $arr[$ub] = DllStructGetData($TE32_Struct, "th32ThreadId") EndFunc ;==>_GetAllThreads_ArrHelper Func _Exit() Exit EndFunc It has worked without any problems in the past. Br, UEZ Edit: was an older version Edited October 12, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2010 Developers Share Posted October 12, 2010 edit: Valuater... Valuater, that sounds familiar. Hmm. You were here before, right?Correct, since 2005 continues... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
trancexx Posted October 12, 2010 Share Posted October 12, 2010 Correct, since 2005 continues...Oh, great! Jurassic park. I'll be driving the Mercedes. ♡♡♡ . eMyvnE 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