gatt

Run script each time a same program is opened!

15 posts in this topic

#1 ·  Posted (edited)

Its possible make a script, to detect each time it a new program x.exe is opened in my pc, and do y action?

Example:

I have a tool that will open 10 of same program, with a delay between each opened program. What i need is: each time this program is opened, the script load y action.

At the end ill need those 10 same .exe with the action loaded in each one;

The program that will opened is the same the 10x, same name, same process name;

Edited by gatt

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

something to get you started !

 this will give you the count of instances .. and check if all instances are paired before starting a new instance 

$count = ProcessList("same.exe")
If Mod($count[0][0], 2) = 0 Then Run("same.exe")

;~ the count of instances
$message = "you have " & $count[0][0] & " instances open"
MsgBox(0, 'Count', $message)

 

Edited by Deye

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I have a tool that will open 10 firefox.exe with a delay of 1 second in each firefox opened, what i need is a script to load this code:

RegWrite("HKCU\Console", "colortable00", "REG_SZ", "Intel i" & Random(6, 9, 1) & "000HQ")

Each time one of those firefox is opened

 

 

-It's Just example

Edited by gatt

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

how about something like this :

Local $iPid, $iSleep

For $x = 0 To 10
    $iPid = Run("C:\Program Files\Mozilla Firefox\firefox.exe http://www.google.com")
    $iSleep = 1000
    Do
        Sleep($iSleep)
        If IsWindowActive($iPid) Then
            RegWrite("HKCU\Console", "colortable00", "REG_SZ", "Intel i" & Random(6, 9, 1) & "000HQ")
            ExitLoop
        Else
            $iSleep += 1000
        EndIf
    Until $iSleep = 4000
Next

Func IsWindowActive($iPID)
    Local $aWinList = WinList()
    For $i = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$i][1]) = $iPID And BitAND(WinGetState($aWinList[$i][1]), 2) Then Return 1
    Next
    Return 0
EndFunc   ;==>IsWindowActive

 

Edited by Deye

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Bro not worked, when i open the program it dont change the registry key.

I need a autoitscript opened in background running all time, and detecting each time x.exe is opened and add that regedit key

Edited by gatt

Share this post


Link to post
Share on other sites

#6 ·  Posted

try adding   #RequireAdmin at the top of the script

if the run command doesn't work try

 $iPid = Run("C:\Program Files\Mozilla Firefox\firefox -new-window http://www.google.com")

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I dont need the script open the program, ill open it manually, i just need it add that regedit key each time i open x program.

For example: each time i open firefox.exe it add

RegWrite("HKCU\Console", "colortable00", "REG_SZ", "Intel i" & Random(6, 9, 1) & "000HQ")

 

Just it, but i need the script keeps in background running and detecting each time firefox.exe is opened and add registry again

Edited by gatt

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

then just use this

#RequireAdmin 
RegWrite("HKCU\Console", "colortable00", "REG_SZ", "Intel i" & Random(6, 9, 1) & "000HQ")

from scite's menu  choose compile to exe or F5 to run ..

Edited by Deye

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

But i need it run only when detect a new "firefox.exe" is opened, even if theres another firefox opened

Edited by gatt

Share this post


Link to post
Share on other sites

#10 ·  Posted

Can you please tell us why you need to open 10 instances of FireFox (or whatever program you need to start)?
Sounds a bit strange to me :huh:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I just dont explained it well, my english not good, what i need is just a script to run a regedit key each time it detects a .exe is opened, forget 10 firefox instances -

I need change one regedit key each time i open a .exe, if possible the script should keep detecting until i close it

Edited by gatt

Share this post


Link to post
Share on other sites

#12 ·  Posted

It's always funny how some persist to remain vague about what it really is they want. 
My view on this is simple: When you can't be bothered to put in some effort to explain and share what you already have then I can't be bothered to assist.

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted

Funny is post in someones topic with the intention of just critic others, instead helps, im not being vague because i want, and just because i cant express it correct, like i said im using google translate to try explain what im looking for

Share this post


Link to post
Share on other sites

#14 ·  Posted

At least I achieved you are willing to type a full sentence now.

Going back to my cave now ;)

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted

I found this script that detects when a new process is found:

Dim $GetProcess , $CompareProcess , $LastArray, $TestThis

$GetProcessTime = TimerInit()
$Check = ''
While 1
    If TimerDiff($GetProcessTime) / 1000 >= 1 Then; checks for a change in process list ever 1 second
        $GetProcess = GetProccessInfo(Chr(01))
        If StringInStr($LastArray, $GetProcess) = 0 Then
            $LastArray = $GetProcess
            $Check = $Check + 1
            If $Check <> 1 Then MsgBox(0, 'Change', 'The Process List Changed')
        EndIf
        $GetProcessTime = TimerInit()
    EndIf
    Sleep(100)
WEnd

Func GetProccessInfo($d_Delimeter)
    Local $n_NowList = ProcessList()
    Local $r_ReturnArray = ''
    For $i = 1 To $n_NowList[0][0]
        $r_ReturnArray = $r_ReturnArray & $n_NowList[$i][0] & $d_Delimeter
    Next
    Return $r_ReturnArray;StringTrimRight($r_ReturnArray, 1)
EndFunc

But how i manage to compare the process name and run a action?

For example, detected a new process is opened, then it checks if this new process name is equal "firefox.exe" then do a action.

 

Share this post


Link to post
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