Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Exe() - Script name = Executable name


  • Please log in to reply
10 replies to this topic
HotKeyIt!
  • Guests
  • Last active:
  • Joined: --
Instead of having several AutoHotkey.exe instances in Task Manager, you can run your script using renamed AutoHotkey.exe.
That way a different name will be used in TaskManager for each script and they are easy to differentiate.

Exe("C:\Temp\MyScript.ahk")

Exe(file){
	Loop,%file%
		Filename:=RegExReplace(A_LoopFileShortName,"\.[^\.]*$")
	Loop,%A_AhkPath%
		path:=A_LoopFileDir
	FileMove,%A_AhkPath%,%path%\%FileName%.exe
	If ErrorLevel
		Return ErrorLevel
	Loop
		Loop,%path%\%FileName%.exe
		{
			Run %A_LoopFileFullPath% "%file%",% RegExReplace(file,"\\[^\\]*$"),,PID
			Process,Wait,%Pid%,5
			FileMove,%A_LoopFileFullPath%,%A_AhkPath%
			Process,Wait,%Pid%,0.1
			Return ErrorLevel
		}
}


SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
Not bad...
I can see where this could be handy.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
I'm glad you like it.

I accidentally used A_LoopFileShortName, A_LoopFileName should be better :)
Exe(file){
	Filename:=RegExReplace(RegExReplace(File ,"^.*\\"),"\.[^\.]*$")
	dir:= SubStr(file,1,InStr(file,"\",1,0))
	Loop,%A_AhkPath%
		path:=A_LoopFileDir
	FileMove,%A_AhkPath%,%path%\%FileName%.exe
	If ErrorLevel
		Return ErrorLevel
	Loop
		Loop,%path%\%FileName%.exe
		{
			Run %A_LoopFileFullPath% "%file%",%dir%,UseErrorLevel,PID
			If (ErrorLevel){
				MsgBox Could not open file.
				Return
			}
			Process,Wait,%Pid%,5
			FileMove,%A_LoopFileFullPath%,%A_AhkPath%
			Process,Wait,%Pid%,0.1
			Return PID
		}
}

:!: NOTE: A script launched by Exe() cannot perform a reload itself as the executable will be not available anymore.

EDIT: working directory will be scripts directory now.

________________________
@Moderator
Due to network refresh, my computer logged off the site and post was created as guest.
Is it possible to delete that one and repost or easily change author?

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
Or if you just want to find out what script each AutoHotkey instance is running, you can use this. :)

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
@ TheGood
Thank you, I've seen that and some other scripts showing processes,
but I like to have that processes called right in Task Manager, because I can have an overview for all programs there,
but also because of the details for the process like CPU usage, RAM usage and more :)

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

A script launched by Exe() cannot perform a reload itself as the executable is renamed back to original name (AutoHotkey.exe) :!:



Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
Am I suppose to add this to my AHK file or what?
Could you give an example of how to use it? sounds nice idea

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Am I suppose to add this to my AHK file or what?
Could you give an example of how to use it? sounds nice idea


You will need to run an ahk script to run another script using Exe(ScriptPath), e.g. save this in an ahk file and double click it:
FileSelectFile,filepath,1,,Select AutoHotkey Script,AutoHotkey Script (*.ahk)
If !ErrorLevel && FileExist(filepath)
	Exe(filepath)


keacey
  • Members
  • 2 posts
  • Last active: Apr 24 2015 06:42 PM
  • Joined: 04 Apr 2014

Hi, I've been looking for something like this without compiling hte script. But i'm a new to ahk and a detailed example to use this script will be very helpful. 

 

Let say i have 3 ahk scripts running - A, B, and C. 

How should i use this above script so that i can rename the process for all 3 scripts?

 

thankyou



HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Simply use additional script to start your other scripts:

Exe("c:\Temp\MyScript1.ahk")
Exe("c:\Temp\MyScript2.ahk")
Exe("c:\Temp\MyScript2.ahk")


bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

i test this. runs fine. other than serious problem with RELOAD-related issues! ;)

; http://www.autohotkey.com/board/topic/38621-exe-script-name-executable-name/

#SingleInstance Force
#NoEnv

FileSelectFile,filepath,1,,Select AutoHotkey Script,AutoHotkey Script (*.ahk)
If !ErrorLevel && FileExist(filepath)
	Exe(filepath)

Exe(file){
	Loop,%file%
		Filename:=RegExReplace(A_LoopFileShortName,"\.[^\.]*$")
	Loop,%A_AhkPath%
		path:=A_LoopFileDir
	FileMove,%A_AhkPath%,%path%\%FileName%.exe
	If ErrorLevel
		Return ErrorLevel
	Loop
		Loop,%path%\%FileName%.exe
		{
			Run %A_LoopFileFullPath% "%file%",% RegExReplace(file,"\\[^\\]*$"),,PID
			Process,Wait,%Pid%,5
			FileMove,%A_LoopFileFullPath%,%A_AhkPath%
			Process,Wait,%Pid%,0.1
			Return ErrorLevel
		}
}