Jump to content
nacerbaaziz

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

Recommended Posts

nacerbaaziz

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
nacerbaaziz

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
Danp2

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
nacerbaaziz

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
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
nacerbaaziz

am sorry for this repitation

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites
nacerbaaziz

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
nacerbaaziz
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
nacerbaaziz

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
Danp2

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.

  • Like 1

Share this post


Link to post
Share on other sites
nacerbaaziz

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
Jos

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

  • Like 1

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     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
nacerbaaziz

IS THE @AutoItPID WORK IF THE SCRIPT IS COMPILED?

Share this post


Link to post
Share on other sites
nacerbaaziz

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

    • simonc8
      By simonc8
      I have a script which executes sleep for a couple of hours then carries out instructions. Does the running AutoIt script prevent the computer from entering sleep mode during this time? If not, is there something I can add to the AutoIt script to keep the computer awake?
      Grateful for advice.
    • gahhon
      By gahhon
      Hi,
      I have a program that is read data from the .txt file, since the .txt file is only readable, viewable and editable for the admin user.
      But how could I lock it with password, or some other technique that can helps to achieve this?
      Thanks for the advanced information.
    • gahhon
      By gahhon
      Hi,
      How can I the trigger the another button functions without waiting the previous function to finish execute?
      Any advise?
      I couldn't find any relevant topics via google.
      Thanks a lot.
    • SharpDressedMan
      By SharpDressedMan
      Hi all,
      I need to use ControlMove() on some controls of a hidden GUI window.
      This works properly on a GUI window created with default style, but does not work on a GUI window created with style $WS_OVERLAPPEDWINDOW
      func GUItest($bOverlapped) $m = GUICreate("test", 200, 100, -1, -1, $bOverlapped ? $WS_OVERLAPPEDWINDOW : -1) $g = GUICtrlCreateButton("test", 0, 0) ControlMove($m, "", $g, 30, 30) GUISetState() endfunc GuiTest(false) ; button 'test' properly moved to (30,30) GuiTest(true) ; button 'test' not moved and still sitting at (0,0) Any reason for this unexpected behavior ?
      Any workaround to fix this ?
      Thanks for any help
    • 2Toes
      By 2Toes
      Hi all..
      I'm having slight issue that has be a bit puzzled.
      I have an Input control.. After a certain function runs, it Disables that Input control, and sets it to ReadOnly.
      When running another certain function, it re-Enables that Input control, and sets the style back to Default.
      Which does work, however, when typing into the Input control after re-Enabling it, the text appears as a light gray color, rather than its original black color.
      I'm sure there's a simple solution here.. But what that is, appears to be beyond me.
      Here is a simplified example code:
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 245, 215, 192, 124) Global $disableBTN = GUICtrlCreateButton("Disable", 32, 64, 75, 25) Global $enableBTN = GUICtrlCreateButton("Enable", 128, 64, 75, 25) Global $Input1 = GUICtrlCreateInput("", 32, 120, 169, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $disableBTN disable() Case $enableBTN enable() EndSwitch WEnd Func disable() GUICtrlSetState($Input1, $GUI_DISABLE) GUICtrlSetStyle($Input1, $ES_READONLY) EndFunc Func enable() GUICtrlSetState($Input1, $GUI_ENABLE) GUICtrlSetStyle($Input1, $GUI_SS_DEFAULT_INPUT) EndFunc  
      Any help would be greatly appreciated
      Thank you in advance!
×