Jump to content

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


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

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