Docfxit Posted May 10, 2020 Posted May 10, 2020 (edited) I've put this code together but I'm having some problems. 1. If the $FilePath is not found I would like it to stop and give me a message. expandcollapse popup#RequireAdmin $FilePath = "C:\Windows.old\Windows\WinSxS" For $i = 1 To 4 Step 1 _GetDir($FilePath) RunWait("C:\Programs\Unlocker\Unlocker.exe", $FileDir / d) Next ; #FUNCTION# ====================================================================================================== ; Name...........: _GetDir ; Description ...: Returns the directory of the given file path ; Syntax.........: GetDir($sFilePath) ; Parameters ....: $sFilePath - File path ; Return values .: Success - The file directory ; Failure - -1, sets @error to: ; |1 - $sFilePath is not a string ; Author ........: Renan Maronni <renanmaronni@hotmail.com> ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; ================================================================================================================== Func _GetDir($sFilePath) Local $aFolders = StringSplit($sFilePath, "\") Local $iArrayFoldersSize = UBound($aFolders) Local $FileDir = "" If (Not IsString($sFilePath)) Then Return SetError(1, 0, -1) EndIf $aFolders = StringSplit($sFilePath, "\") $iArrayFoldersSize = UBound($aFolders) For $i = 1 To ($iArrayFoldersSize - 2) $FileDir &= $aFolders[$i] & "\" Next Return $FileDir EndFunc ;==>_GetDir ; #FUNCTION# ====================================================================================================== ; Name...........: _GetFileName ; Description ...: Returns the file name of the given file path ; Syntax.........: GetFileName($sFilePath) ; Parameters ....: $sFilePath - File path ; Return values .: Success - The file name ; Failure - -1, sets @error to: ; |1 - $sFilePath is not a string ; Author ........: Renan Maronni <renanmaronni@hotmail.com> ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =================================================================================================================== Func _GetFileName($sFilePath) Local $aFolders = "" Local $FileName = "" Local $iArrayFoldersSize = 0 If (Not IsString($sFilePath)) Then Return SetError(1, 0, -1) EndIf $aFolders = StringSplit($sFilePath, "\") $iArrayFoldersSize = UBound($aFolders) $FileName = $aFolders[($iArrayFoldersSize - 1)] Return $FileName EndFunc ;==>_GetFileName Edited May 10, 2020 by Docfxit
Nine Posted May 10, 2020 Posted May 10, 2020 Not really an autoit question, is it ? But there you go... The object of Unlocker can be a text file containing a list of files to be deleted (unlocked). unlocker.exe ListofFiles.txt -L -D For each folder do a _FileListToArray and write the result with _FileWriteFromArray, and RunWait the command (untested) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Docfxit Posted May 10, 2020 Author Posted May 10, 2020 (edited) I tried following your instructions with this code: expandcollapse popup; This will use the program Unlocker.exe to delete folders and files in $FilePath #RequireAdmin #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> AutoItSetOption("ExpandVarStrings", 1) Global $aFileList[35] Global $FilePath = "C:\Config.Msi" $aFile = @ScriptDir & "\UnlockerListofFiles.txt" _GetFolders() _FileWriteFromArray($aFile, $aFileList, 1) If @error Then MsgBox(0, "", '@Error = ' & @error & @CRLF & "@extended = " & @extended) ;Add $FilePath to list of files in the path _AddRecord() RunWait(@ComSpec & " /c C:\Programs\Unlocker\Unlocker.exe" & " " & $aFile & " -L -S -D -O") Exit Func _GetFolders() ; List all the files and folders in the desktop directory using the default parameters. $aFileList = _FileListToArray($FilePath, "*", $FLTA_FILESFOLDERS, True) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") Exit EndIf EndFunc ;==>_GetFolders Func _AddRecord() Local $hFileOpen = FileOpen($aFile, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf ; Write data to the file using the handle returned by FileOpen. FileWrite($hFileOpen, $FilePath) ; Close the handle returned by FileOpen. FileClose($hFileOpen) ; Display the contents of the file passing the filepath to FileRead instead of a handle returned by FileOpen. ;MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & FileRead($aFile)) EndFunc ;==>_AddRecord Edited May 18, 2020 by Docfxit This is my final code
water Posted May 10, 2020 Posted May 10, 2020 What's the value of @error after _FileWriteFromArray? Doesn't the line unlocker.exe ListofFiles.txt - L - D need a bit of a brush up? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 10, 2020 Author Posted May 10, 2020 Thanks for the reply... I was just thinking it does. I'm trying to figure this out one step at a time. I currently have that line commented out. I'm trying to get it to write the file. Thanks,
Docfxit Posted May 10, 2020 Author Posted May 10, 2020 (edited) 1 hour ago, water said: What's the value of @error after _FileWriteFromArray? I updated the above code. The @Error = 2 @Extended =0 Edited May 10, 2020 by Docfxit
water Posted May 10, 2020 Posted May 10, 2020 $aFileList is defined as local so it gets destroyed when the function ends. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 10, 2020 Author Posted May 10, 2020 Thanks for catching that. I changed the above code. Now I'm getting @Error = 1
water Posted May 10, 2020 Posted May 10, 2020 @ScriptDir is not enough! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 10, 2020 Author Posted May 10, 2020 (edited) 2 hours ago, water said: @ScriptDir is not enough! Thank you. I changed the code above. That did fix the last problem. I have a new problem. The Runwait either isn't running or I don't have the parms correct because it isn't deleting the files. It does write the list of files. on the list, The first line is a folder and the next line is a file. Panther SetupPlatform.ini Edited May 11, 2020 by Docfxit
water Posted May 11, 2020 Posted May 11, 2020 @ScriptDir and $aFile are treated literally at the moment so unlocker does not read the correct file. Either concatenate this variables so AutoIt can resolve them or use AutoItSetOption("ExpandVarStrings", 1) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 11, 2020 Author Posted May 11, 2020 (edited) 17 hours ago, water said: @ScriptDir and $aFile are treated literally at the moment so unlocker does not read the correct file. Either concatenate this variables so AutoIt can resolve them or use AutoItSetOption("ExpandVarStrings", 1) Thank you for the suggestion... I tried AutoItSetOption("ExpandVarStrings", 1 and that didn't work. So I concatenated the two fields. I have changed the code above so you could see what I did. The current code is bringing up the GUI. It's not selecting the files or paying any attention to the options. When the GUI comes up it is not in delete mode. Thank you, Edited May 11, 2020 by Docfxit
water Posted May 12, 2020 Posted May 12, 2020 (edited) Try: Run("C:\Programs\Unlocker\Unlocker.exe " & $aFile & " /L /D") Maybe you need to set the workingdir too: Run("C:\Programs\Unlocker\Unlocker.exe " & $aFile & " /L /D", "C:\Programs\Unlocker") BTW: Nine used a "-" for the command line parameters. You are using "/". Make sure to use the correct delimiter. Edited May 12, 2020 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 12, 2020 Author Posted May 12, 2020 Thank you for the suggestions... They both bring up the same Unlocker screen. They don't select the correct options and they don't run. This is the screen they bring up: This is the help screen. The / or the - works the same way. I have tried them both. I realize you are flying blind. I know the program is hard to find on the internet. Would you like me to send it to you? Thanks, Docfxit
water Posted May 12, 2020 Posted May 12, 2020 With Google's help I found it in a second I do not think it is an AutoIt related problem in the first place. So I suggest you open a DOS window and play with the command line options until it works for you. Then wrap it in AutoIt as suggested above. If you encounter problems then, come back to this forum My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 13, 2020 Author Posted May 13, 2020 I discovered the script does find all files in the folder: $FilePath = "C:\$WINDOWS.~BT\Sources" When it writes out the file with this line: _FileWriteFromArray($aFile, $aFileList, 1) It writes out the files and folders that are in $FilePath. This is what the file looks like: example.au3 Panther ProcessEx.au3 SetupPlatform.ini When that file is passed to Unlocker the file names don't include the $FilePath. What Unlocker needs is a file that looks like this: C:\$WINDOWS.~BT\Sources\example.au3 C:\$WINDOWS.~BT\Sources\Panther C:\$WINDOWS.~BT\Sources\ProcessEx.au3 C:\$WINDOWS.~BT\Sources\SetupPlatform.ini How can I add the path to each file ? Thanks, Docfxit
water Posted May 13, 2020 Posted May 13, 2020 Guess how to add the path? How do you create the list of files in the first place? Recheck the parameters of this command My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 13, 2020 Author Posted May 13, 2020 11 hours ago, water said: Guess how to add the path? How do you create the list of files in the first place? Recheck the parameters of this command Thank you for guiding me in the right direction. I made a change that does include the path now. I think the change I made could be simpler and more elegant but I couldn't find a good example on how to streamline it. Thanks, Docfxit
water Posted May 13, 2020 Posted May 13, 2020 Simpler? You just needed to fix this line $aFileList = _FileListToArray($FilePath, "*", $iFlag = $FLTA_FILESFOLDERS, $bReturnPath = True) to $aFileList = _FileListToArray($FilePath, "*", $FLTA_FILESFOLDERS, True) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Docfxit Posted May 13, 2020 Author Posted May 13, 2020 14 minutes ago, water said: Simpler? You just needed to fix this line $aFileList = _FileListToArray($FilePath, "*", $iFlag = $FLTA_FILESFOLDERS, $bReturnPath = True) to $aFileList = _FileListToArray($FilePath, "*", $FLTA_FILESFOLDERS, True) That's super. Thank you very much. Just what I needed. The file is written correctly now. I just need to get Unlocker running now.
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