Jump to content

Recommended Posts

Posted (edited)

Greetings again.

I am trying to make a program that will detect if it is already running, and if so, will pass information received via a command line parameter to the first instance of the program, then exit the second instance.

I have searched the forums for an hour trying to find a solution, but to no avail. I'm sure it's been discussed before.

Typically, I use the console for debugging my uncompiled scripts (in SciTE), but never used it for compiled scripts before.

Anyhow, here are snippets of what I have so far (Compiled script is named "VideoLan.exe")....

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

If $CmdLine[0] = 1 Then
    $sSourceFile = $CmdLine[1]
EndIf

$aProcess = ProcessList("VideoLan.exe")
if $aProcess[0][0] > 1 Then
        ConsoleWrite("VideoLan: " & $sSourceFile)
        Exit 0
EndIf

<gui stuff goes here>

While 1
    If ConsoleRead(0,true) > 0 Then
        $sCon = ConsoleRead()
        if StringLeft($sCon,8) = "VideoLan" Then
            GUICtrlSetData ($gSourceInput,StringMid($sCon,11))
        EndIf
    EndIf
    Sleep(100)
WEnd

<functions go here>

I think that the ConsoleRead/ConsoleWrite isn't the correct functions for what I need. I looked at StdoutRead/StdoutWrite, but from what I understood, that would only work for child processes, which this program wouldn't apply.

Thank you in advance,

-Trystian

PS: I'm using AutoIT 3.2.2.0

Edited by TrystianSky
Posted (edited)

neogia's method (second link) using standard i/o steam to communcate between 'threads' which (in my mind) would be the standard method. If you elimnate std i/o, tcp, file and registry access as communcation types your really not left with much else besides direct memory modfications (you dont wanna do that).

Edited by evilertoaster
  • Moderators
Posted

If you are speaking of your own AutoIt App.. _SingleTon() will kill the 2nd instance, and you could always write to a file for the 1st instance to check occasionally if it must know the 2nd instance was ever launched, maybe with AdlibEnable() (to check periodically).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

I've actually done something like this before with a program I created.

I just wanted it to activate itself if you ran the program again. This is what I used.

#region - unique run
Global $s_AutoItWinTitle = 'AutoIt3.FireKey.Window'
If WinExists($s_AutoItWinTitle) Then
    ControlSetText($s_AutoItWinTitle, '', 'Edit1', 'SHOW')
    Exit
EndIf
AutoItWinSetTitle($s_AutoItWinTitle)
#endregion
Posted (edited)

Ok, I got it to work now, and here's the code....

#include <GUIConstants.au3>
Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1)

if $CmdLine[0] = 1 Then
    $sSourceFile = $CmdLine[1]
EndIf

$aProcess = ProcessList(@ScriptName)
if $aProcess[0][0] > 1 Then
    $handle = WinGetHandle("classname=AutoIt v3 GUI","VideoLan Stream Launcher")
    ControlSetText($handle,"","Edit1",$sSourceFile,0)
    WinActivate($handle)
    Exit 0
EndIf

<gui stuff goes here>

While 1
    Sleep(100)
WEnd

<functions go here>

Thank you all for the assistance. :whistle:

Edited by TrystianSky

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
  • Recently Browsing   0 members

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