Docfxit Posted July 2, 2017 Share Posted July 2, 2017 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 More sharing options...
Danp2 Posted July 2, 2017 Share Posted July 2, 2017 You may want to look into using @ProgramFilesDir and ProcessExists. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Xandy Posted July 2, 2017 Share Posted July 2, 2017 (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 July 2, 2017 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Docfxit Posted July 3, 2017 Author Share Posted July 3, 2017 (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 July 3, 2017 by Docfxit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now