Jump to content
Sign in to follow this  
rsjabbens

Start program when window is not active

Recommended Posts

rsjabbens

Hello,

I'm looking for some way to start an executable if it is not running. We have a server that is running 3 programs for scheduler software. These 3 programs are always needed to run. There is always the same user logged on to this server and the server is locked when someone is not using it.

I have used this to test:

Global $Paused, $Runner
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMe")

While 1
    Sleep(100)
WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc  ;==>Terminate

Func ShowMe()
    $Runner = Not $Runner
    While $Runner
        Sleep(2000)
        If WinExists("C:\Windows\system32\cmd.exe") Then
    ;Nothing to do  
        Else
        Run("D:\autoit\files\test.bat")
        EndIf
        Sleep(2000)
        If WinExists("Naamloos -") Then
    ;Nothing to do  
        Else
        Run("notepad.exe")
        EndIf
    WEnd
EndFunc  ;==>ShowMe

This is working, the only thing i don't now, how can i start this directly when the script is started (without using a key)? And what is the best way to start it, using the startup folder, creating a service or using some registry key to start this?

Thanks in advance,

Roland

Share this post


Link to post
Share on other sites
jerem488

Hello,

Do you want start your script when your computer is locked, so not used ???


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
rsjabbens

Hello,

Do you want start your script when your computer is locked, so not used ???

Yes and no, the script needs to be always running, it needs to be started at least when the specific user is logged in and also stay running when the computer is locked.

I already found the command for the script to directly run the function with the "CALL" command. At the moment my script look like this:

Global $Paused, $Runner
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMe")

While 1
    Sleep(100)
    Call ("ShowMe")
WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc  ;==>Terminate

Func ShowMe()
    $Runner = Not $Runner
    While $Runner
        Sleep(2000)
        If WinExists("C:\Windows\system32\cmd.exe") Then
    ;Nothing to do  
        Else
        Run("D:\autoit\test.bat")
        EndIf
        Sleep(2000)
        If WinExists("Naamloos -") Then
    ;Nothing to do  
        Else
        Run("notepad.exe")
        EndIf
    WEnd
EndFunc  ;==>ShowMe

So what to do, i was thinking to start it from the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, i think that should work. The only thing i'm thinking, is there a way to create a system tray icon when the script is active to just let me (or someone else) know that the script is active and give information about the script (like how to stop it e.g.).

Roland

Share this post


Link to post
Share on other sites
herewasplato

... These 3 programs are always needed to run. There is always the same user logged on to this server ...

While 1
    If Not ProcessExists("processname1") Then Run("full path to exe1")
    If Not ProcessExists("processname2") Then Run("full path to exe2")
    If Not ProcessExists("processname3") Then Run("full path to exe3")
    Sleep(1000)
WEnd
Post back if you do not understand how to modify the code above to meet your needs.

Install AutoIt on the server.

Place the script as an AU3 text file in the "All Users" start up folder and you are done.

You can compile the script if you want, but you run the risk that at some point in the future your antivirus program may quarantine it. You can run it as a service if you want, but you will need to learn about how to do so - and again, there is a risk of the AV sw quarantining the EXE.

As far as an icon in the system tray, "give information about the script (like how to stop it e.g.)" the code above will have the normal AutoIt icon in the system tray and just clicking on that icon pauses the script as well as shows the user how to exit the script. If you want more than that, post back.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
rsjabbens
While 1
    If Not ProcessExists("processname1") Then Run("full path to exe1")
    If Not ProcessExists("processname2") Then Run("full path to exe2")
    If Not ProcessExists("processname3") Then Run("full path to exe3")
    Sleep(1000)
WEndoÝ÷ Øú,µ¶'ò¢çhn׫²Ö§v0¶¨v'ò¶¡×nÞ¶zܨº¹ÞyÛËZP.-¢{azÇ«½êϧ¶¬r¸©µ«7µìm~)^{az«¨´   eRÇ«²«¨¶ËZ®Û©~]z¶§w*.j·¢w¢çÊ&¦)^¶¬r¸©¶'ò¢ìÖî·*.®éíêâ²KajÖ­²¦§¶)íçî¶êÞÊ«j{b¾*î²è¶¦¬ª¹ªÚاz+X¢ç»§Ö¬jÇ«¾'ü¨»§µ»­Ê°Ygyçm¢W®v¢ëa£hv(jwZ¨§¶«z+®+$¡ûaxl«­©íx§Ø^q±ö«jƧÊ'{az̬µé­­¬ªºbn¯z)ߢ¹¶*'.¶Ø^±Êâ¦ÙbèhÂÚ,¶bµè?oøªºmç(uæ¢÷°Yaj÷­éè®f¥ëh"Ø¢x§¶¬ÊË^ÚÚÉ©Ýë-rX)à¢{ajØ¢zZºÇ¬¶¬r¸©µ«0zYZ²ÈhÂËazë®0¶±ÛazÇ+H*.Á©íÞ¶§¶­¦-m§$þ«¨µäájy2¢çè®Ø^­êeÉ8b²+0¢¹"î²×âæî¶'hmÁ©í¶§²Ö¥­ hØ^±êïz¸°Yn±ëayÊ&¦)^v÷«²*''ßÛm)䶭¥ë¶¬jƬz»âqæÞq«¬zØ^­íý±©pk+ºÇ«¶­ç²ÚzZ çh+ay-«Z±êïǨ¢²wuçpéì¢g­)àj[(ç²Ú+º|"¶.µ©î±êå¢v)ө䱨}÷N¬ËayË«­éí~ée±Êâ¦Ü"¶±jjezèqë,©±«­¢+Ù±½°ÀÌØíAÕÍ°ÀÌØíIÕ¹¹È)!½Ñ-åMÐ ÅÕ½ÐííAUMôÅÕ½Ðì°ÅÕ½ÐíQ½±AÕÍÅÕ½Ðì¤)!½Ñ-åMÐ ÅÕ½ÐííM
ôÅÕ½Ðì°ÅÕ½ÐíQɵ¥¹ÑÅÕ½Ðì¤)!½Ñ-åMÐ ÅÕ½ÐííåôÅÕ½Ðì°ÅÕ½ÐíM¡½Ý5ÅÕ½Ðì¤()]¡¥±Ä(%M±À ÄÀÀ¤(%
±° ÅÕ½ÐíM¡½Ý5ÅÕ½Ðì¤)]¹()Õ¹Q½±AÕÍ ¤(ÀÌØíAÕÍô9½ÐÀÌØíAÕÍ(]¡¥±ÀÌØíAÕÍ(M±À ÄÀÀ¤(Q½½±Q¥À ÌäíMÉ¥ÁÐ¥ÌÅÕ½ÐíAÕÍÅÕ½ÐìÌäì°À°À¤(]¹(Q½½±Q¥À ÅÕ½ÐìÅÕ½Ðì¤)¹Õ¹ìôôÐíQ½±AÕÍ()Õ¹Qɵ¥¹Ñ ¤(á¥ÐÀ)¹Õ¹ìôôÐíQɵ¥¹Ñ()Õ¹M¡½Ý5 ¤(ÀÌØíIÕ¹¹Èô9½ÐÀÌØíIÕ¹¹È(]¡¥±ÀÌØíIÕ¹¹È($%M±À ÈÀÀÀ¤($%%9½ÐAɽÍÍá¥ÍÑÌ ÅÕ½ÐíAɽÍÌĹáÅÕ½Ðì¤Q¡¸IÕ¸ ÅÕ½ÐíAɽÍÌĹáÅÕ½Ðì¤($%%9½ÐAɽÍÍá¥ÍÑÌ ÅÕ½ÐíAɽÍÌȹáÅÕ½Ðì¤Q¡¸IÕ¸ ÅÕ½ÐíAɽÍÌȹáÅÕ½Ðì¤($%%9½ÐAɽÍÍá¥ÍÑÌ ÅÕ½ÐíAɽÍÌ̹áÅÕ½Ðì¤Q¡¸IÕ¸ ÅÕ½ÐíAɽÍÌ̹áÅÕ½Ðì¤(%]¹)¹Õ¹ìôôÐíM¡½Ý5

Share this post


Link to post
Share on other sites
nguyenbason

I think i will better if you make a GUI for this monitor program.

- Display status

- Write log for each time it don't run, start ...

:D


UnderWorldVN- Just play the way you like it

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.