Jump to content

Recommended Posts

Posted (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.

 

#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 by Docfxit
Posted

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)

Posted (edited)

I tried following your instructions with this code:

; 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 by Docfxit
This is my final code
Posted

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

 

Posted

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,

Posted (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 by Docfxit
Posted

$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

 

Posted

@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

 

Posted (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 by Docfxit
Posted

@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

 

Posted (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 by Docfxit
Posted (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 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

 

Posted

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:

Unlocker.jpg.7736db7e889afcbc321c65c61d04198c.jpg

This is the help screen.  The / or the - works the same way.  I have tried them both.

UnlockerCommandLine.jpg.05b9829df99f1f77e0c82933ec1305cd.jpg

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

Posted

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

 

Posted

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

Posted

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

 

Posted
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

Posted

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

 

Posted
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.

 

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...