Docfxit

If a program isn't running I'd like to run it

4 posts in this topic

#1 ·  Posted

I would like this code to launch Salamander if it's not running.

If _OSVersion() = 'Win7' Or _OSVersion() = 'Win7SP1' Or _OSVersion() = 'Win7X64' Or _OSVersion() = 'Win7SP1x64' Then
    $ProgramFiles = "C:\Programs\"
Else
    $ProgramFiles = "C:\Program Files\"
EndIf

Opt("WinTitleMatchMode", 2) ; Match any part of the title
If WinActive("Salamander") = 0 Then ;0 means the window is not active
    Run($ProgramFiles & "\Salamander\salamand.exe")
    Do
        Sleep(50)
    Until WinActive("Salamander") = 1
EndIf

If salamander isn't running this script won't run it.  Why?

This is what Window Info shows as the title  "9xAddons - Altap Salamander 3.08 (x86) EDU (Administrator)"

This is what Task Manager shows as the program name when it is running: salamand.exe

Thanks,

Docfxit

Share this post


Link to post
Share on other sites



#2 ·  Posted

You may want to look into using @ProgramFilesDir and ProcessExists.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If Salamander has it's own window then this will work.

You will need to delete my test values and unremark your own.  I also cut out the code that I didn't have functions for.  You probably want to add that back in as well or look into Dan2p's suggestion of:  @ProgramFilesDir  :)

 

$program_exe = "Gimp 2\bin\gimp-2.8.exe"
;$program_exe = "Salamander\salamand.exe"
$sWinTitle = "GNU Image Manipulation Program"
;$sWinTitle = "Salamander"

;If _OSVersion() = 'Win7' Or _OSVersion() = 'Win7SP1' Or _OSVersion() = 'Win7X64' Or _OSVersion() = 'Win7SP1x64' Then
;    $ProgramFiles = "C:\Programs\"
;Else
    $ProgramFiles = "C:\Program Files\"
;EndIf

ConsoleWrite($ProgramFiles & $program_exe)

Opt("WinTitleMatchMode", -2) ; Match any part of the title negitave to ignor case

If WinExists($sWinTitle) = 1 Then
    ; Window exists so activate it
    WinActivate($sWinTitle)
Else
    ; Run filepath to make window exist
    Run($ProgramFiles & $program_exe)
    WinActivate($sWinTitle)
EndIf
; Wait for window to be active, wait no more then 6 seconds
WinWaitActive($sWinTitle, "", 6)

 

It's possible that more then one window will match and we might need to look into WinList()

You can let me know if it's not working as expected.

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

56 minutes ago, Xandy said:

If Salamander has it's own window then this will work.

You will need to delete my test values and unremark your own.  I also cut out the code that I didn't have functions for.  You probably want to add that back in as well or look into Dan2p's suggestion of:  @ProgramFilesDir  :)

 

$program_exe = "Gimp 2\bin\gimp-2.8.exe"
;$program_exe = "Salamander\salamand.exe"
$sWinTitle = "GNU Image Manipulation Program"
;$sWinTitle = "Salamander"

;If _OSVersion() = 'Win7' Or _OSVersion() = 'Win7SP1' Or _OSVersion() = 'Win7X64' Or _OSVersion() = 'Win7SP1x64' Then
;    $ProgramFiles = "C:\Programs\"
;Else
    $ProgramFiles = "C:\Program Files\"
;EndIf

ConsoleWrite($ProgramFiles & $program_exe)

Opt("WinTitleMatchMode", -2) ; Match any part of the title negitave to ignor case

If WinExists($sWinTitle) = 1 Then
    ; Window exists so activate it
    WinActivate($sWinTitle)
Else
    ; Run filepath to make window exist
    Run($ProgramFiles & $program_exe)
    WinActivate($sWinTitle)
EndIf
; Wait for window to be active, wait no more then 6 seconds
WinWaitActive($sWinTitle, "", 6)

 

It's possible that more then one window will match and we might need to look into WinList()

You can let me know if it's not working as expected.

That worked excellent.  ;-)

Thank you very very much,

Docfxit

Edited by Docfxit

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