General program Launcher

Post gaming related scripts
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

General program Launcher

08 Nov 2015, 01:05

This is a ready to use scrip for launching/starting the application of you're choice and it's soul purpose is just that. Meaning you need to create you're own functions for sending key's or whatever you want to do with some application. It's well documented so you should be able to understand what each feature does and why it does what it does.

Key Features:
- Simple animated Gui for displaying script variables and settings.
- Added the following buttons: Start you're application, Set administrative rights, Clear variables, and Exit script. They should speak for them self.
- A Admin mode for when the game/program is not excepting input from the script.
- The Gui remembers it's position.
- All variables are written to the script it self.
- Only operates (sending key's etc) to the window that you specify.
- Partially compatible with steam.(working on it)
- Tray icon is that of the program to work with. And for the moment a basic menu item added.

Changes:
- Replaced old if(admin = true) for creating RunAssAdmin button with variable Elevate.
- When elevated. A reset back to user credentials tels the user to manually restart.
- Gui starts centered when launched for the first time, ore after a script reset.
- changed some inconsistent ore sloppy code here and there.
- Improved the process to close feature. When the application did not quit within 5 seconds aggressively terminating it.
- Changed the weird way I enabled the script to run as admin. the code is much simpler now.

ToDo:
Gui needs some fixing.Margins are not optimal so they need to be changed to "relative to"

Code: Select all

/*
[Variables]
AppToRun=
Path=
ExeFile=
WinTitle=
WinClass=
SteamID=
Admin=False
Elevate=RunAsAdmin
[GuiPoss]
xPoss=
yPoss=
*/
;--------------------------Auto Execute Section. Ends where first return is encountered--------------------------
#NoEnv                                      ;Empty variables will not be checked if there system environment variables.
#Persistent                                 ;Script may not close until it receives a ExitApp command.
#NoTrayIcon                                 ;Switching tray icon off until the application to work with is started.
#KeyHistory 0                               ;Not needed when only running the script.
;#Warn, all, StdOut                      	;All known error to standard output.
#SingleInstance off                         ;The script is allowed to run multiple instances of itself.
ListLines, off                              ;Not needed when only running the script.
SetTitleMatchMode, 3                        ;Variables for wintitle must be a exact match to the value in parameter window title. Whatever it's ahk_exe, ahk_class, ahk_id, etc it must exactly match!
SendMode, Input                             ;Send command uses the input method. The SetKeyDelay is ignored by SendInput and send in this case.
SetKeyDelay, 100, 50                        ;Delay for sending keystrokes and press duration time. For use with the SendEvent command.
SetBatchLines, -1                           ;Never sleep script in between execution, 'while its running'. Maximum CPU clock.
SetWorkingDir, %A_ScriptDir%                ;Set the script to use it's full folder path as it's working directory. In variable A_ScriptDir, the last backslash is excluded.
;--------------------------Place global variables here--------------------------

;--------------------------Reading variables and adding there content--------------------------
IfExist, %A_ScriptName%
{
    IniRead, AppToRun, %A_ScriptName%, Variables, AppToRun
    IniRead, Path, %A_ScriptName%, Variables, Path
    IniRead, ExeFile, %A_ScriptName%, Variables, ExeFile
    IniRead, WinTitle, %A_ScriptName%, Variables, WinTitle
    IniRead, WinClass, %A_ScriptName%, Variables, WinClass
    IniRead, SteamID, %A_ScriptName%, Variables, SteamID
    IniRead, Admin, %A_ScriptName%, Variables, Admin, False
    IniRead, Elevate, %A_ScriptName%, Variables, Elevate, RunAsAdmin
    IniRead, ScriptEnabled, %A_ScriptName%, Variables, ScriptEnabled, No
    IniRead, xPoss, %A_ScriptName%, GuiPoss, xPoss
    IniRead, yPoss, %A_ScriptName%, GuiPoss, yPoss
}
If(Admin = "True")           ;Cheking if admin is enabled.
{
    if not A_IsAdmin           ;Checking if the script is elevated, if you just do a Run *RunAs then closing the script. You get trapped in a infinite loop!
    {
        Run *RunAs "%A_ScriptFullPath%"
        ExitApp
    }
}
;--------------------------Asking for user input when variable 'AppToRun' at the top of this script is blank--------------------------
again:
If(AppToRun = "")           ;Checking if AppToRun is empty.
{
    InputBox, AppToRun, , Specify path and executable name of the program you want to start. e.g. "x:\folder\file.exe",,600,130,,,,,
    If(ErrorLevel = 1)           ;The user pressed cancel.
    {
        Exitapp
    }
    Else if(ErrorLevel = 0)
    { 
        If(AppToRun = "")
        {
            MsgBox, , , You pressed ok`, but nothing was specified!`nPlease try again, 5
            gosub, Again
            return
        }
        Else if(AppToRun != "")
        {
            RegExMatch(AppToRun, "[\w](.*\\)", Path)           ;RegEx filter for extracting the path to the application from variable 'AppToRun' and putting it in new variable 'Path'
            RegExMatch(AppToRun, "[\s\w]+[.][\w]*", ExeFile)           ;RegEx filter for extracting the filename and extension from variable 'AppToRun'. Placing it in new variable 'ExeFile'
                                                                    	    ;This second filter is not depended on type of file/extension.
                                                                                                                       
            IniWrite, %AppToRun%, %A_ScriptName%, Variables, AppToRun
            sleep, 10
            IniWrite, %Path%, %A_ScriptName%, Variables, Path
            sleep, 10
            IniWrite, %ExeFile%, %A_ScriptName%, Variables, ExeFile
            sleep, 10
             
            IniRead, AppToRun, %A_ScriptName%, Variables, AppToRun           ;Getting the value for 'AppToRun' once more, otherwise the tray icon might fail at first run.
        }
    }
}
;--------------------------Creating tray menu and drawing script GUI--------------------------
Menu, tray, Icon  
Menu, tray, Icon, %AppToRun%
Menu, tray, add
Menu, tray, add, Quit Script and %WinTitle%, GuiClose

Gui +LastFound
Gui, Add, GroupBox, x3 y40 w316 h216 , 
Gui, Add, Text, x8 y5 w296 h36 vAppToRun, Path and executable name:`n%AppToRun%
Gui, Add, Text, x8 y56 w296 h36 VWinTitle, Window Title: `n%WinTitle%
Gui, Add, Text, x8 y108 w296 h36 VWinClass, WindowClass:`n%WinClass%
Gui, Add, Text, x8 y159 w296 h36, Admin Enabled:`n%Admin%
Gui, Add, Text, x8 y209 w296 h36 vScriptEnabled, Script is curently enabled:`n%ScriptEnabled%
Gui, Add, GroupBox, x2 y256 w316 h76
Gui, Add, Button, x8 y266 w76 h28, Start
Gui, Add, Button, x84 y266 w76 h28, Stop
Gui, Add, Button, x162 y266 w76 h28, Reset GUI
Gui, Add, Button, x239 y266 w76 h28, Exit Script
Gui, Add, Button, x84 y298 w76 h28, Open Folder
Gui, Add, Button, x239 y298 w76 h28, Exit Application
Gui, Add, Button, x8 y298 w76 h28, %Elevate%
If(xPoss = "" || yPoss = ""){
    Gui, Show, xCenter yCenter, Application Launcher
}else{
    Gui, Show, x%xPoss% y%yPoss%, Application Launcher
}
Script_Gui:=WinExist()
return 
;--------------------------Starting the program, getting WindowClass and title--------------------------
ButtonStart:
IfWinNotExist, ahk_exe %ExeFile%
{
    If(SteamID != "")           ;This code will executed when the SteamID holds some value.
    {
        run, steam://rungameid/%SteamID%
        WinWait, ahk_exe %ExeFile%
        WinWaitActive, ahk_exe %ExeFile%
        WinGet, Process_ID, PID, ahk_exe %ExeFile%
    }Else{                                      ;Below code is executed when variable SteamID empty.
        run, %AppToRun%,%Path%, , Process_ID
        WinWait, ahk_pid %Process_ID%
        WinActivate, ahk_pid %Process_ID%
        WinWaitActive, ahk_pid %Process_ID%
    }
    If(WinTitle = "")           ;When variable WinTitle is empty, getting the window title and writing it back to the script for later use.
    {
        WinGetTitle, WinTitle, ahk_pid %Process_ID%, , Application Launcher
        GuiControl, , WinTitle, Window Title:`n%WinTitle%           ;Displaying/writing the new content of variable WinTitle in the GUI.
        IniWrite, %WinTitle%, %A_ScriptName%, Variables, WinTitle           ;Writing the new content of variable WinTitle back to the script for later use.
        sleep, 10
    }
    If(WinClass = "")           ;Again with a blank variable, getting the window class and writing it back to the GUI and script for later use.
    {
        WinGetClass, WinClass, ahk_pid %Process_ID%, , Application Launcher
        GuiControl, , WinClass, WindowClass:`n%WinClass%
        IniWrite, %WinClass%, %A_ScriptName%, Variables, WinClass
        sleep, 10
    }
}else{           ;If it is not true, it is not running. Then it must be running.  :D
    WinActivate, ahk_exe %ExeFile%
    WinWaitActive, ahk_exe %ExeFile%
    WinGet, Process_ID, PID, ahk_exe %ExeFile%

    If(WinTitle = "")
    {
        WinGetTitle, WinTitle, ahk_pid %Process_ID%, , Application Launcher
        GuiControl, , WinTitle, Window Title:`n%WinTitle%
        IniWrite, %WinTitle%, %A_ScriptName%, Variables, WinTitle
        sleep, 10
    }
    If(WinClass = "")
    {
        WinGetClass, WinClass, ahk_pid %Process_ID%, , Application Launcher
        GuiControl, , WinClass, WindowClass:`n%WinClass%
        IniWrite, %WinClass%, %A_ScriptName%, Variables, WinClass
        sleep, 10
    }
}
GroupAdd, WindowGroup, ahk_class %WinClass%           ;Creating a window group in case variables mismatch or left blank. Also the context sensitive directive #IfWinActive/exist doesn't allow variables names.
GroupAdd, WindowGroup, ahk_exe %ExeFile%           ;With GroupAdd the parameter of the window title can be variable when using the #IfWin directive.
ScriptEnabled=Yes
GuiControl, , ScriptEnabled, Script is curently enabled: `n%ScriptEnabled%
Gui, Submit, NoHide
Process, WaitClose, %Process_ID%

ScriptEnabled=No
GuiControl, , ScriptEnabled, Script is curently enabled: `n%ScriptEnabled%
Gui, Submit, NoHide
return
;--------------------------Section for the program you want the script to work/operate on--------------------------
;Operations will only execute on the window class ore executable name. Opening some other window that happens hold/start with the same name as the window title will be ignored by the script.
#IfWinActive, ahk_group WindowGroup
{
/*
        DO SOMETHING HERE, LIKE SENDING SOME INPUT, GETTING APPLICATION RELATED VALUE'S, ORE MINIPULATE MEMORY.
*/
}
Return
;--------------------------Quit the program to work with--------------------------
ButtonExitApplication:
WinClose, ahk_pid %Process_ID%
While(Process_ID != "")
{
    WinGet, Process_ID, PID, ahk_exe %ExeFile%
    sleep, 1000
    If(A_Index >= 5)           ;Forcing process to terminate if it's still running after 5 seconds. 
    {
        Process, close, %Process_ID%
        break
    }else{
    	continue
    }
}
return           ;Since the script is waiting for the program to close, return jumps to the line where it's waiting (Process, WaitClose, %Process_ID%)
;--------------------------Stop the script from operating on the program to work with--------------------------
ButtonStop:
ScriptEnabled = No
Process_ID =
GuiControl, , ScriptEnabled, Script is curently enabled:`n%ScriptEnabled%
Gui, Submit, NoHide
return
;--------------------------Clear all variables, resetting the script to its defaults--------------------------
buttonResetGUI:
AppToRun=
Path=
ExeFile=
WinTitle=
WinClass=
SteamID=
Process_ID=
ScriptEnabled=No
Admin=False
Elevate=RunAsAdmin
xPoss=
yPoss=
IniWrite, %AppToRun%, %A_ScriptName%, Variables, AppToRun
sleep, 10
IniWrite, %Path%, %A_ScriptName%, Variables, Path
sleep, 10
IniWrite, %ExeFile%, %A_ScriptName%, Variables, ExeFile
sleep, 10
IniWrite, %WinClass%, %A_ScriptName%, Variables, WinClass
sleep, 10
IniWrite, %WinTitle%, %A_ScriptName%, Variables, WinTitle
sleep, 10
IniWrite, %Admin%, %A_ScriptName%, Variables, Admin
sleep, 10
IniWrite, %Elevate%, %A_ScriptName%, Variables, Elevate
sleep, 10
IniWrite, %SteamID%, %A_ScriptName%, Variables, SteamID
sleep, 10
IniWrite, %xPoss%, %A_ScriptName%, GuiPoss, xPoss
sleep, 10
IniWrite, %yPoss%, %A_ScriptName%, GuiPoss, yPoss
sleep, 10
;Writing new content to the GUI window.
GuiControl, , WinTitle, Window Title: `n%WinTitle%
GuiControl, , WinClass, WindowClass:`n%WinClass%
GuiControl, , AppToRun, Path and executable name:`n%AppToRun%
GuiControl, , ScriptAdmin, Admin Enabled:`n%Admin%
GuiControl, , ScriptEnabled, Script is curently enabled:`n%ScriptEnabled%
Gui, Show, xCenter yCenter, Application Launcher
Return
;--------------------------Run the script with administrative privileges --------------------------
/* 
Because of security reasons you should only enable this if the game/application does 
not except input from the script. I advice against running scripts as admin by default! 
*/
ButtonRunAsAdmin:
WinGetPos, xPoss, yPoss, , , Application Launcher
Admin=True
Elevate=RunAsUser
IniWrite, %Admin%, %A_ScriptName%, Variables, Admin
sleep, 10
IniWrite, %Elevate%, %A_ScriptName%, Variables, Elevate
sleep, 10
IniWrite, %xPoss%,  %A_ScriptName%, GuiPoss , xPoss
sleep, 10
IniWrite, %yPoss%, %A_ScriptName%, GuiPoss , yPoss
sleep, 10
DllCall("AnimateWindow","UInt",Script_Gui,"Int",500,"UInt","0x90000")
Run *RunAs "%A_ScriptFullPath%"
ExitApp
return
ButtonRunAsUser:
WinGetPos, xPoss, yPoss, , , Application Launcher
Admin=False
Elevate=RunAsAdmin
IniWrite, %Admin%, %A_ScriptName%, Variables, Admin
sleep, 10
IniWrite, %Elevate%, %A_ScriptName%, Variables, Elevate
sleep, 10
IniWrite, %xPoss%,  %A_ScriptName%, GuiPoss , xPoss
sleep, 10
IniWrite, %yPoss%, %A_ScriptName%, GuiPoss , yPoss
sleep, 10
DllCall("AnimateWindow","UInt",Script_Gui,"Int",500,"UInt","0x90000")
Gui, hide 
MsgBox, 48, , The script is running with elevated previlages. Therefore`, the script can not restart itself using user credentials. A user is not allowed to do anything in a admin environment. The next time you start the script it will run as user.
ExitApp
Return
;--------------------------Opens the installation directory of the program to opereta on--------------------------
ButtonOpenFolder:
Run, Explorer.exe "%Path%"
Return
;--------------------------Writing variables. Exit script--------------------------
GuiClose:
ButtonExitScript:
WinGetPos, xPoss, yPoss, , , Application Launcher
sleep, 10
IniWrite, %AppToRun%, %A_ScriptName%, Variables, AppToRun
sleep, 10
IniWrite, %Path%, %A_ScriptName%, Variables, Path
sleep, 10
IniWrite, %ExeFile%, %A_ScriptName%, Variables, ExeFile
sleep, 10
IniWrite, %WinClass%, %A_ScriptName%, Variables, WinClass
sleep, 10
IniWrite, %WinTitle%, %A_ScriptName%, Variables, WinTitle
sleep, 10
IniWrite, %SteamID%, %A_ScriptName%, Variables, SteamID
sleep, 10
IniWrite, %xPoss%,  %A_ScriptName%, GuiPoss , xPoss
sleep, 10
IniWrite, %yPoss%, %A_ScriptName%, GuiPoss , yPoss
sleep, 10
DllCall("AnimateWindow","UInt",Script_Gui,"Int",500,"UInt","0x90000")
ExitApp
Last edited by megnatar on 20 Jun 2016, 19:33, edited 66 times in total.
Everything we call real is made of things that cannot be regarded as real!
N.Bohr.

Really, that probability is true!
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

14 Nov 2015, 21:23

Update:

- Numpad0 hotkey added. It gets WindowTitle and Class in case they mismatch with those of the window to work with. If it seems the script is not working you can now press Numpad0 while the window is active to get the right value's. If the script still fails after that then press Numpad0 again to permanently give the script administrative privileges.

- Added the program executable to the ahk_group for better compatibility.

- Added a few lines for future compatibility with Steam, not fully working yet.
Everything we call real is made of things that cannot be regarded as real!
N.Bohr.

Really, that probability is true!
User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: General program Launcher

16 Nov 2015, 04:40

I don't have a numberpad on my laptop or main computer.
PatrickSto
Posts: 3
Joined: 16 Nov 2015, 06:48

Re: General program Launcher

16 Nov 2015, 07:12

Run1e This is only your problem...
Look at my website and get facetime for android http://facetimeforandroidapk.com/ here.
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

16 Nov 2015, 07:44

Then you should buy a real computer! Indeed not my problem :D laptops are not made to play games with.. Just because you can doesn't mean it's made for it.
Take a hike on the free way...you can, but I strongly advice against it. Unless you don't value you're life. :yawn:
Everything we call real is made of things that cannot be regarded as real!
N.Bohr.

Really, that probability is true!
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher v1.0

18 Nov 2015, 06:54

Made this as final release and also some minor things changed.


-Writing variable name of A_ScriptFullPath to the admin script instead of it's content.
Last edited by megnatar on 14 Jun 2016, 04:15, edited 1 time in total.
Everything we call real is made of things that cannot be regarded as real!
N.Bohr.

Really, that probability is true!
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

05 Dec 2015, 16:16

Update:

- Replaced the 2 inputboxes with only one and using regex to get executable name from path.
- Added a simple, and for the moment ugly, gui
- Removed the numpad0 hotkey.
- Added comments for clarification.
- Corrected a lot of typo's and removed white spaces.
- Made the code more consistent. Changed code blocks that had to much or to view tabs.That sort of thing.
manish77

Re: General program Launcher

28 Feb 2016, 05:11

I too don't have the number pad
manish
Posts: 1
Joined: 28 Feb 2016, 05:05

Re: General program Launcher

28 Feb 2016, 05:12

I too don't have the numpad on my computer
visit my blog to know more about the streaming app and play box hd alternative app http://playboxhdv3.com
User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Contact:

Re: General program Launcher

28 Feb 2016, 11:24

Hey

Why not change this:
InputBox, AppToRun, , Specify path and executable name of the program you want to start. e.g. "x:\folder\file.exe",,600,130,,,,,

to this:

FileSelectFile, AppToRun, 3, , Select a exe, Game (*.exe)
:yawn:
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

04 Mar 2016, 06:55

I've been away for a while and did not have much time to write updates and respond to PM's. It will be like that for the next half year. Never the less, here is a small update of this script because the previous version contained some flaws.
sharekhan
Posts: 1
Joined: 10 Jun 2016, 11:36
Contact:

Re: General program Launcher

10 Jun 2016, 11:40

It took lot of time for me to do so. You have given a great method to launch the program. Followed the instructions manual without missing and got great results.
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

14 Jun 2016, 04:14

sharekhan wrote:It took lot of time for me to do so. You have given a great method to launch the program. Followed the instructions manual without missing and got great results.
Thanks you for the positive reaction. :superhappy:
Indeed launching a program is one thing, doing it correctly is a other. There for, this script is still under development.
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

14 Jun 2016, 04:23

SnowFlake wrote:Hey

Why not change this:
InputBox, AppToRun, , Specify path and executable name of the program you want to start. e.g. "x:\folder\file.exe",,600,130,,,,,

to this:

FileSelectFile, AppToRun, 3, , Select a exe, Game (*.exe)
sry for the late replay.
Well is was not aware of the FileSelectFile command..
I will check later if it suits my needs.

Thanks for the tip!
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Re: General program Launcher

20 Jun 2016, 18:11

Update:

Changes:
- Replaced old if(admin = true) for creating RunAssAdmin button with variable vElevate.
- When elevated. A reset back to user credentials tels the user to manually restart.
- Gui starts centered when launched for the first time, ore after a script reset.
- changed some inconsistent ore sloppy code here and there.
- Improved the process to close feature. When the application did not quit within 5 seconds aggressively terminating it.

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 35 guests