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                                How to post scriptsource        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

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • e45678mail
      By e45678mail
      Hi~
      I have some question about how to enable the test mode via "Run" or "shellexecute" of command,
      was to tried :
      -----
      Run("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      and
      shellexecute("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      -----
      since this command must to run through administrator competence,
      have any method can accomplish it?
       
       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next