Jump to content

Recommended Posts

Posted

I have below code to check for particular set of files.

For that I am using the function _FileListToArrayRec

Which has filter to check for particular file or with wildcard.

So, the code is written to call three times.

Instead, is there any filter you can suggest, instead of calling the search for 3 times like below.

 

#include-once
#include <Array.au3>
#include <Date.au3>
#include <file.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>

Func LogData($sMessage,$sLogFile=@ScriptDir&"\Logging.log")
    If $sMessage = "" Then
        FileWriteLine($sLogFile, "")
    Else
        FileWrite($sLogFile,_NowCalc() & " :: " & $sMessage&@CRLF)
    EndIf
EndFunc

Func DeleteFiles($sFilter)
    Local $hFilesFolders = _FileListToArrayRec("C:", $sFilter,$FLTAR_FILES, $FLTAR_RECUR)
    _ArrayDisplay($hFilesFolders)

    For $i=0 to $hFilesFolders[0]
        Local $iReturn = FileDelete($hFilesFolders[$i])
        LogData("Ran delete for : "& $hFilesFolders[$i] &" with error code: "&$iReturn)
    Next
EndFunc

DeleteFiles("*.au3")
DeleteFiles("*.txt")

 

Posted

Thank you.

Is there any option for Killing a process also by providing range of names like this?

  • Developers
Posted
  On 10/12/2020 at 9:47 AM, ur said:

Is there any option for Killing a process also by providing range of names like this?

Expand  

What do you think the answer is?

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

Posted (edited)

I thought to keep a function separately to call ProcessClose inside it.

And split the input string at ; semicolon.

And call the processclose one by one.

But, the complete process name should be passed to it.It is not accepting wilcards.

Is there any function someone already posted that supports wildcards? 

 

Got this, 

 

But is there any more simpler one?

Edited by ur
Posted

Below code I tried but not closing the multiple notepads and wordpads.

Func ProcessCloseList($sProcessList)
    Local $aProcess = StringSplit($sProcessList, ";")
    Local $list = ProcessList()
    For $j = 1 To $aProcess[0]
        Local $i = 1
        For $i = 1 To $list[0][0]
            Local $temp = "^"& $aProcess[$j] &".*$"
            ConsoleWrite($aProcess[$j]&" - "&$temp&@CRLF)
            If StringRegExp($list[$i][0], $temp) Then
                ConsoleWrite("Trying to close process with ID: "& $list[$i][0])
                Local $preturn = ProcessClose($list[$i][0])
                ConsoleWrite(" - "&$preturn & " - "&@error)
            EndIf
        Next
    Next
EndFunc

ProcessCloseList("wordpad;notepad")

 

  • Developers
Posted

.. ok ..  I see you are getting somewhere.
So what is the problem you think?  Are you getting any matches and is it actually trying to close a process? 
Maybe add some error/returncode checking in your code so you know why it is failing?

Jos
 

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

Posted

The "@error" value is 3

3 = TerminateProcess Failed

 

No details other than that.

But with windows taskkill command the process is closed.

Posted

Single process it is working fine.

If I launch like 5 notepad.exe then it is closing 1/2 in them

 

Posted

ok, but present I used taskkill directly.

RunWait(@SystemDir&"\taskkill.exe /f /im "&$list[$i][0])

  • Developers
Posted

Again: Have you tried using the PID in stead of process name with ProcessClose()?

  Quote

Remarks

The array returned is two-dimensional and is made up as follows:
    $aArray[0][0] = Number of processes
    $aArray[1][0] = 1st Process name
    $aArray[1][1] = 1st Process ID (PID)
    $aArray[2][0] = 2nd Process name
    $aArray[2][1] = 2nd Process ID (PID)

Expand  

 

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

Posted

Hi, yes with process ID it is terminating.

 

Func ProcessCloseList($sProcessList)
    Local $aProcess = StringSplit($sProcessList, ";")
    Local $list = ProcessList()
    For $j = 1 To $aProcess[0]
        Local $i = 1
        For $i = 1 To $list[0][0]
            Local $temp = "^"& $aProcess[$j] &".*$"
            If StringRegExp($list[$i][0], $temp) Then
                ConsoleWrite("Trying to close process with ID: "& $list[$i][1]);0 for name of process
                Local $preturn = ProcessClose($list[$i][1])
                ;Local $preturn=RunWait(@SystemDir&"\taskkill.exe /f /im "&$list[$i][0])
                ConsoleWrite(" - "&$preturn & " - "&@error&" - "&@extended)
            EndIf
        Next
    Next
EndFunc

ProcessCloseList("wordpad;notepad")

 

Posted
  On 10/12/2020 at 3:05 PM, Jos said:

Sure...

Expand  

And yet, on my machine at least, if you have 6 notepads open, you will have to invoke the script at least 4 separate times to kill them all.

As for the RegEx challenge, the record shows my initial interest, which faded when I failed to locate the canonical challenge :)

 

Code hard, but don’t hard code...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...