Sign in to follow this  
Followers 0
fanoI

Shell Integration

8 posts in this topic

#1 ·  Posted (edited)

Hello to all!

I've written a little script to control a remote program via telnet (Console Telnet v2.0 in reality) to send file with specific extension (simple association using "Open With..." :) ) and in particular web links with specific protocol (In this case changing the registry keys...)

The script works but I think it is a little ineffiecient if I click on more file at once...

1) Click on link1 on firefox

2) Windows recognize the association and open my autoIt script

3) My script open telnet and send the link...

4) Maybe in the meantime I click on link2...

5) Another script starts contemporary, open a NEW telnet connection and.. so on

If I'm verrry fast I can have 10 instances that is 10 telnet... and weird things could be happen...

I like a lot if my script can operate in a message way (now I use the $CmdLine[1] variable) that is always in execution on tray area

and when I click on that links or files type on Firefox (but maybe the Windows Shell or another browser... must be indifferent) my appl in the tray regain life and

do the operations...

; These will be configurable parameters

$g_IP = "YourIP"         ; Server's IP
$INFO  = 0
$WARN  = 1
$ERROR = 3

; I want to start the telnet process only one time!
$telnetPID = startTelnet()
If $telnetPID == -1 Then
    ShowMessage($ERROR, "Program termination for previous errors")
    Exit
EndIf

While 1; main loop 
        $message = WHATFUNCTION can I use?  I though ConsoleRead() but does nothings!

        If isFile($CmdLine[1]) Then
          SendFile($telnetPID)
         Else
           Sendlink($telnetPID); This a link address
        EndIf
Wend

; It's time to die... but before Cleanup!

StdinWrite($telnetPID, "close"); See you later Lphant!

ProcessClose($telnetPID, 1)

Exit

Another problem but of secondary importance, for now, is that if the script is already in execution (in a while) and I click on a link/file the shell open

another instance of it... there is a way to change this behavior?

I see a lot of programs doing this... I like a lot that my app can do it as well...

Thanks for the help,

fanoI

Edited by fanoI

Share this post


Link to post
Share on other sites



Try again, aim for conciseness. I read this twice and still don't understand exactly what you want..

If I read what you want correctly:

One way would be to add an else condition that sets a flag when you assign a valid $telnetid, and only start a new process

if that flag isn't set...

WRT limiting the number of instances of an app, search for valik's singleton function, or mutex. The help file also has a basic method of ensuring that only one copy of an app runs that involves setting / testing for a windows name. You can also use file or registry semaphores, etc.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Sorry english is not my mother tongue... I try to be more clear :)

The first problem is that I want only one process that start on clicking on it or on the click of files with the extension associated to it and stay in the tray and if

I click again on the file process it...

As emule and other programs, do for example...

Now I use CommandLineRaw and this work as Firefox pass it as a parameter, but if my script it is already in execution I don't know how to read that data...

For the second problem I think to have solved almost... I use ProcessWaitClose function to wait that old telnet istance (and my script) is terminated... but I

like that there was only one process always running that does all...

fanoI

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is this impossible to do with AutoIt?

I think that ConsoleRead doesn't works really I've tried the communication of 2 script sender & recevier and recevier loops forever (nothing TO READ!!!)

I'm doing something wrong?

;sender

$pid = ProcessExists("receiver.exe")

If ($pid == 0) Then
    MsgBox(0, "", "Processo non trovato")
    $pid = Run("receiver.exe", "", 3)
EndIf

StdinWrite($pid, "blah blah blah")

Exit

;recevier

While 1
    $charwaiting = ConsoleRead(0, 1)
    
    If ($charwaiting <> 0) Then
        $currentRead = ConsoleRead()
        MsgBox(0, "", "Letto: " & $currentRead)
    EndIf
WEnd

ConsoleRead is supposed to be used to read my own standard input... but maybe Firefox/The Shell doesn't use this mechanism to comuncate the parameter but in this case with 2 AutoIt script MUST work...

Maybe I can use a script opened by the Shell to send its CommandLine to the real program... writing in its stdin, but if ConsoleRead does nothing :)

Thanks for the help,

fanoI

Edited by fanoI

Share this post


Link to post
Share on other sites

Is this impossible to do with AutoIt?

I gave you methods to do what you've asked, as best I understand what you've asked, strongly implying the answer to your question above is NO.

Please remember that Autoit is a WINDOWS application, not a console mode application. It is likely that the 'console....' functions are not doing what you think they should, because AUTOIT APPLICATIONS ARE NOT CONSOLE MODE APPLICATIONS.

Search for 'makecui' , 'editbin', and _RunReadStd() if you want to convert an autoit application to a console mode application, and use it as such.

Of course other methods (file , registry, IPC) to name just a few can be used for inter process communication other than stdout/stdin/stderr.

HTH


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

I'm not trying to communicate with a console application but with Firefox!

I hoped that other that give me the files/link as a parameter when I open it it give me it on my stdin... but it don't seems to do it... (or ConsoleRead doesn't work at all)

Thanks for the help,

fanoI

Share this post


Link to post
Share on other sites

if you want a script to pick up command line parameters given from another script you can use $cmdline for that, search the help file for how to use it.


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

I know that I can use Command Line Parameters to talk with another script... but only on the Run/RunWait statement... my second script

will be always in execution in a while and regain life when I "see" a new file/link for the remote program is required.

But I like to evitate to use 2 scripts... I like to have only one that in some way listen Firefox (or Windows Shell - Explorer I don't know who is that send the file

to associated app when I press open with... / click on a associated protocol) as Lphant or Emule do... that is I don't want a new istance started but the old running istance intercept the file process it and then continues its normal execution.

Thanks for the help,

fanoI

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
Sign in to follow this  
Followers 0