Jump to content

If dynamic exe process closes , run it


Recommended Posts

Hi there,

I'm fairly new to AutoIT and have done some researches to perform what I want I want to check if process is running, if not, it will run it, or whenever it closes.

Problem is process name is dynamic, it changes on every restart of the process (but path is always the same), so far is my script but doesn't seem to do anything:

#include <MsgBoxConstants.au3>

$search = FileFindFirstFile("*.exe")
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
Else
    $file = FileFindNextFile($search)
    $Exe = @ScriptDir & '\' & $file
 EndIf

$StartTimer = TimerInit() ; Define the initial time we will be comparing to later
Checkprocess() ; Run our checkprocess() function on initial execute
While 1 ; Infinite Loop Condition is always true, you can exit these loops with "ExitLoop"
    If TimerDiff($StartTimer) > 60000 Then ; Only run the conditional code if the difference in time is greater than 1 min (60000 Miliseconds)
        Checkprocess()
    EndIf
    Sleep(10) ; So we don't kill the CPU
WEnd ; End of While Loop
Func Checkprocess()
   $search = FileFindFirstFile("*.exe")
    If WinExists("[TITLE:C:\Users\Zeus\Downloads\Test\; CLASS:ConsoleWindowClass]") Then
       MsgBox($MB_SYSTEMMODAL, "", "Window exists")
    Else
      Run($exe) ; checks if process exists.. If not, it will Run the process
       MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Window does not exist")
    $StartTimer = TimerInit() ; Reset the timer since the script just ran
    EndIf
EndFunc   ;==>Checkprocess

Thanks for any help.

Link to comment
Share on other sites

2 minutes ago, argumentum said:

I recon that if it needs a dynamic name is a virus and that AutoIt it's too slow for it.

I don't know what you're trying to say, but if you think i'm trying to run a virus, please use some common sense.

Link to comment
Share on other sites

Try this, if you dare:

While WinWaitClose("[TITLE:C:\Users\Zeus\Downloads\Test\; CLASS:ConsoleWindowClass]")

   If Run(@ScriptDir & '\' & FileFindNextFile(FileFindFirstFile("*.exe"))) Then 
      WinWait("[TITLE:C:\Users\Zeus\Downloads\Test\; CLASS:ConsoleWindowClass]")
   Else
      Sleep(60000)
   EndIf
  
WEnd

Makes a few assumptions, based on your original code:

1) That you are running this script as an .au3 file using the interpreter, with the working directory being the same one that the "dynamic" .exe will magically appear.

2) That when the .exe process terminates, there is another new .exe file in the directory to run AND the old .exe has been removed. If the old one is not removed, it may run it again, depending on the way the files are returned.

3 If no .exe file is found it will check every minute for one

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

Link to comment
Share on other sites

  • Moderators

iamzeus_,

You need to close the handle returned from FileFindFirstFile - although I would strongly suggest using _FileListToArray to replace it when looking for the exe file you wish to run.

And like the others, i am somewhat bemused by an exe that continually changes its process name - can you give us some more detailed information as to just what it is you are doing as it might help us give you some more focused advice on how to solve your problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

45 minutes ago, Melba23 said:

You need to close the handle returned from FileFindFirstFile

Does that go for me also, even though I don’t actually assign the handle to a variable.  I could be wrong, but I feel in Java for instance, the GC would realize that there are no references to the handle(s) at some point, and reclaim the memory.

Does Autoit have something like that?

Edit: Never mind, because of the stateful nature of FileFindFirst and Next, I don’t think it could be released even if Autoit has GC.

Edited by JockoDundee

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

Link to comment
Share on other sites

9 hours ago, argumentum said:

so, what is the reason mr. common sense ?

Most of the viruses nowadays automatically run by themselves even when trying to remove/close etc, so I don't see why I would need AutoIT to do that.
Not trying to be arrogant or whatever, but if you're really think I'm trying to run a virus, thats pretty dumb.

Anyways, the reason is that the program will get timestamp process name, based on the time its been started, as simple as that.

If you don't want to help, that's fine, don't, but having to justify myself when I don't need to...

Link to comment
Share on other sites

  • Moderators

iamzeus_,

There is no need to get your knickers in a twist - I am sure the comment was made in jest. And now you have explained about the timestamp can we please all get along nicely.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

26 minutes ago, iamzeus_ said:

Anyways, the reason is that the program will get timestamp process name, based on the time its been started, as simple as that.

How does the process die, on its own?

How does its .exe file get removed from the dir?

Should the restart program (this new script) be restarting the .exe with the latest time stamp/name?

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

Link to comment
Share on other sites

1 hour ago, iamzeus_ said:

Anyways, the reason is that the program will get timestamp process name, based on the time its been started, as simple as that.

hmmm, what are you upto .... .

1 hour ago, iamzeus_ said:

If you don't want to help, that's fine, don't, but having to justify myself when I don't need to...

I'd like to help but you are very defensive. What are you hiding .... .

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Source code looks a lot like a bot written in AutoIT a while back. Similar functionality. Even the test and pause at start. Executing random named executable files.

Sorry, no help from me until the local gas station has fuel in stock again.

Link to comment
Share on other sites

  • Moderators

Confuzzled,

Quote

Source code looks a lot like a bot written in AutoIT a while back. Similar functionality. Even the test and pause at start. Executing random named executable files.

Is this just a random accusation or do you have a link?

M23

Edit: Found it:

Which links back to here:

 

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

iamzeus_,

You have now managed to make a lot of people suspicious, so let us make this formal. What is this mysterious exe file you want to keep running but which alters its process name with a timestamp? A lot more information please.

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

1 hour ago, Melba23 said:

Confuzzled,

Is this just a random accusation or do you have a link?

M23

Edit: Found it:

Which links back to here:

 

 

I copied/pasted the examples above, yes, as I said in my first post, I did some researches and found those threads.

Link to comment
Share on other sites

  • Moderators

iamzeus_

Can you see the "Moderator" tag under my avatar? That means that until you convince me about your "good intentions" you will get no help here. So best you start explaining exactly why you are trying to keep a seemingly random exe file (which uses a timestamp as part of its process name) alive and well.

Over to you  - and the clock is running.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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