nacerbaaziz

how to detect if an other copy from the same script if runing

31 posts in this topic

#1 ·  Posted

Hello
How are you
I have a question, please.
I've created a window and i need
when i run the script if it detect an other copy from the same script was runing
 the script close the first copy Automatically and run a new copy
I want an example to understand it

Share this post


Link to post
Share on other sites



#2 ·  Posted

Look up _Singleton in the help file. Also, search the forum and you will likely find other suggested solutions.

Share this post


Link to post
Share on other sites

#3 ·  Posted

i find _Singleton but i don't know how to close the first copy if exist please help me

Share this post


Link to post
Share on other sites

#4 ·  Posted

Look at ProcessList. Compare the PID to @AutoItPID and then use ProcessClose to close any other instances.

Again, I'm sure you could find some full working examples if you put some effort into searching the forums.

Share this post


Link to post
Share on other sites

#5 ·  Posted

so i've created a audio player

and i need when the users open a audio file if the software find an other audio file was playing it will close the old

and i don't know how to do that

Please help me if there is any way to do this.

Share this post


Link to post
Share on other sites

#6 ·  Posted

Danp2 exactly described what to do. What have you tried so far?


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

#7 ·  Posted (edited)

am sorry for this repitation

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites

#8 ·  Posted

In fact, all my attempts were unsuccessful
I apologize for bothering you all this time because of my poor understanding of this. If there is no inconvenience I want a simple example to explain to me
I would be thankful to all of you
Greetings to you, right you are a good peoples

Share this post


Link to post
Share on other sites

#9 ·  Posted

8 minutes ago, nacerbaaziz said:

In fact, all my attempts were unsuccessful

Show us what you tried in your failed attempts. Post your code.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Here's some examples that you would have found if you tried searching the forums --

 

Edited by Danp2

Share this post


Link to post
Share on other sites

#11 ·  Posted

56 minutes ago, Danp2 said:

Here's some examples that you would have found if you tried searching the forums --

 

 

where is it?

thank you

Share this post


Link to post
Share on other sites

#13 ·  Posted

Hello
I apologize very much for bothering you all
But it's very important to me
I will now try to explain in detail what I want to do and please help me with this
1. I designed an audio player called easy audio player
The executable file name is easyAudioPlayer.exe
Its task is to play audio files
I have made this player the default in opening my audio files.
2 What I want is if you press an audio file if the program finds another file that is open in the same program, it will closes it and opens the file that was pressed
This is exactly what I want
please help
By typing a simple example,
Greetings to all of you and I repeat my apologies
I apologize for my weak English

Share this post


Link to post
Share on other sites

#14 ·  Posted

You should stop apologizing about your English and instead apologize for your lack of effort in solving the issue for yourself.

You've been given pointers on how to do it. Now how about you show some code showing where you've actually tried to solve it yourself instead of repeatedly asking for someone else to write the code for you.

1 person likes this

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I tried writing this function but it did not work
Please correct the error if any
Greetings
Thank you very much

 

Func check($exefile = @ScriptName, $HWND = $hGUI)
    Local $process = $exefile, $window = $HWND, $return
    Local $iPID = WinGetProcess($window)
    If @error Then Return -1
    Local $aProcessList = ProcessList($process)
    If @error Then Return -1
    For $i = 1 To $aProcessList[0][0]
        If Not $aProcessList[$i][1] = $iPID Then
            ProcessClose($aProcessList[$i][1])
        EndIf
    Next
    Return 1
EndFunc   ;==>check

 

Edited by Jos

Share this post


Link to post
Share on other sites

#16 ·  Posted

Something like this?

Func check($exefile)
    Local $OwnPID = @AutoItPID
    Local $aProcessList = ProcessList($exefile)
    If @error Then Return -1
    For $i = 1 To $aProcessList[0][0]
        If Not $aProcessList[$i][1] = $OwnPID Then
            ProcessClose($aProcessList[$i][1])
        EndIf
    Next
    Return 1
EndFunc   ;==>check

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

#17 ·  Posted

IS THE @AutoItPID WORK IF THE SCRIPT IS COMPILED?

Share this post


Link to post
Share on other sites

#19 ·  Posted

Unfortunately my dear i tried it and did not work
When I opened an audio file I worked plain
when i opened the other file did not close the first and remained listening to the two file

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

  • Similar Content

    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
      Brian
    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help