Hi all,
At https://www.autohotkey.com/docs/v2/Program.htm#title the help says that at least somewhere in the script's main title there should be the value of A_ScriptFullPath by default.
I now have a script that seems to have just the name of the ahk file as its title by default. No path. Strangely enough, other scripts that I am running at the same time have the expected title according to help.
Do any of you readers know of some circumstance that could cause that? (Assuming that the code does not change the title on purpose.)
Thx and regards, me
Script's main title is missing path - any ideas why? Topic is solved
Re: Script's main title is missing path - any ideas why?
The link you posted is regarding the script’s “main window”, which is normally hidden and appears when you double-click on the script’s tray icon.
Re: Script's main title is missing path - any ideas why?
Yes, indeed. Thx for replying. However, what are you trying to say? Do you think that the phrase "script's main title" could be referring to something else? If so, to what? My issue indeed is with the title of the script's main window.
Re: Script's main title is missing path - any ideas why?
It seemed to me that you may be referring to an untitled GUI or MsgBox that is produced by your script, which by default show the script’s name (not full path).
Re: Script's main title is missing path - any ideas why?
Ok, I see, thx for clarifying.
Re: Script's main title is missing path - any ideas why?
Ok, (I found out) more info:
The main goal is to reload all currently running ahk scripts.
I basically do something like this (a bit more complex and both in v1 and v2) without the timer:
viewtopic.php?t=95051#p422339
Now, I found out that the one script (which I am talking about up above) actually appears twice in the WinGetList list.
One time with the expected full path in the title of its main window.
And then with a second window carrying only the ahk file name as title.
This happens when I run it with Run ... from the code.
When I run it manually via the file explorer, then the WinGetList list even has one more window extra (when checking with Script.Length) which mysteriously disappears (WinExist("ahk_id ID") is 0 all of a sudden) before I can get its title.
Could this have anything to do with the AutoHotkeyUX.exe and the launcher.ahk?
The main goal is to reload all currently running ahk scripts.
I basically do something like this (a bit more complex and both in v1 and v2) without the timer:
viewtopic.php?t=95051#p422339
Now, I found out that the one script (which I am talking about up above) actually appears twice in the WinGetList list.
One time with the expected full path in the title of its main window.
And then with a second window carrying only the ahk file name as title.
This happens when I run it with Run ... from the code.
When I run it manually via the file explorer, then the WinGetList list even has one more window extra (when checking with Script.Length) which mysteriously disappears (WinExist("ahk_id ID") is 0 all of a sudden) before I can get its title.
Could this have anything to do with the AutoHotkeyUX.exe and the launcher.ahk?
Last edited by autocart on 02 Nov 2023, 11:02, edited 1 time in total.
Re: Script's main title is missing path - any ideas why?
I found out the title of the initially elusive window by checking it earlier in the code:
[user folder]\AppData\Local\Programs\AutoHotkey\UX\launcher.ahk - Autohotkey v2.0.2
So this one is the launcher.
How high are the chances that the other window also has to do with it?
Is there a more robust way of how to reload all currently running scripts?
[user folder]\AppData\Local\Programs\AutoHotkey\UX\launcher.ahk - Autohotkey v2.0.2
So this one is the launcher.
How high are the chances that the other window also has to do with it?
Is there a more robust way of how to reload all currently running scripts?
Re: Script's main title is missing path - any ideas why?
If you're saying that the other window(s) have only the file name and not the full path, then it would seem that you could just close each script then run it to reload it. Something like this:
Code: Select all
DetectHiddenWindows 1
ThisScriptFullPath := '...' ; fill in path to script
WinClose ThisScriptFullPath ' ahk_class AutoHotkey'
WinWaitClose ThisScriptFullPath ' ahk_class AutoHotkey'
Run '"' ThisScriptFullPath '"'
Re: Script's main title is missing path - any ideas why? Topic is solved
Yes, but I don't want to have to keep a manually edited list like that.
Anyway, I found out the reason, now:
I had this line in the script:
Gui +LastFound
The ONLY line dealing with the Gui, so that I could do the following:
vHWnd := WinExist()
I had thought that that would refer to the script's main window, since I am not doing anything else Gui related.
Well, obviously that one simple Gui line is already creating a new window for the script in the background, which is not the script's main window, but a new window.
At least, I can now be at ease, knowing that I can ignore that extra Gui window.
And I also found out about the launcher windows on the way, which is also a good thing.
Thanks for sticking through with me, boiler.
Regards, me
Anyway, I found out the reason, now:
I had this line in the script:
Gui +LastFound
The ONLY line dealing with the Gui, so that I could do the following:
vHWnd := WinExist()
I had thought that that would refer to the script's main window, since I am not doing anything else Gui related.
Well, obviously that one simple Gui line is already creating a new window for the script in the background, which is not the script's main window, but a new window.
At least, I can now be at ease, knowing that I can ignore that extra Gui window.
And I also found out about the launcher windows on the way, which is also a good thing.
Thanks for sticking through with me, boiler.
Regards, me
Re: Script's main title is missing path - any ideas why?
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
F5:: {
; Passing Command Line Parameters to a Script
; https://www.autohotkey.com/docs/v2/Scripts.htm#cmd
Msgbox "A_ScriptFullPath:`n" A_ScriptFullPath
Msgbox "A_ScriptPID`n" A_.ScriptPID
Msgbox GetProcessCreationFileTime(A_.ScriptPID)
Msgbox "A_.CommandLine:`n" A_.CommandLine
for args in A_.Argv
Msgbox "A_.Argv[" A_Index "]:`n" args
Msgbox "A_.Argc:`n" A_.Argc
Msgbox "A_.CommandLineExecutablePath:`n" A_.CommandLineExecutablePath
Msgbox "A_.CommandLineArguments:`n" A_.CommandLineArguments
}
Class A_
{
static ScriptPID {
get {
static CurrentProcessId:=DllCall("Kernel32.dll\GetCurrentProcessId", "UInt")
return Format("{:d}",CurrentProcessId)
}
}
/*
A_.CommandLine
A_.Argv
A_.Argv[i]
A_.Argc
A_.CommandLineExecutablePath
A_.CommandLineArguments
*/
static CommandLine {
get {
static vCommandLine:=GetCommandLine()
return vCommandLine
}
}
static Argv {
get {
static vArgv:=CommandLineToArgvW(A_.CommandLine)
return vArgv
}
}
static Argc {
get {
static vArgc:=A_.Argv.Length
return vArgc
}
}
static CommandLineExecutablePath {
get {
static vCommandLineExecutablePath:=A_.Argv[1]
return vCommandLineExecutablePath
}
}
static CommandLineArguments {
get {
static vArguments:=RegExReplace(RegExReplace(GetCommandLine(),"s)^(?:`"\Q" A_.CommandLineExecutablePath "\E`"|\Q" A_.CommandLineExecutablePath "\E)(.*)","${1}"),"s)^ (.*)","${1}")
return vArguments
}
}
}
GetCommandLine() { ; v1.1 v2.0
return DllCall("Kernel32.dll\GetCommandLine", "Str")
}
CommandLineToArgvW(CmdLine:="") { ; v2.0
args:=[]
if (pArgs:=DllCall("Shell32.dll\CommandLineToArgvW", "WStr",CmdLine, "Ptr*",&nArgs:=0, "Ptr")) {
Loop nArgs
args.Push(StrGet(NumGet((A_Index-1)*A_PtrSize+pArgs,"Ptr"),"UTF-16"))
DllCall("Kernel32.dll\LocalFree", "Ptr",pArgs)
}
return args
}
; CommandLineToArgvW function (shellapi.h)
; https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw
GetProcessCreationFileTime(PID) {
static PROCESS_QUERY_INFORMATION:=0x0400, PROCESS_VM_READ:=0x0010
if !(hProcess:=DllCall("OpenProcess", "UInt",PROCESS_QUERY_INFORMATION+PROCESS_VM_READ, "Int",0, "UInt",dwProcessId:=PID, "Ptr"))
return false
DllCall("GetProcessTimes", "Ptr",hProcess, "Int64*",&lpCreationTime:=0, "Int64*",&lpExitTime:=0, "Int64*",&lpKernelTime:=0, "Int64*",&lpUserTime:=0)
DllCall("CloseHandle", "Ptr",hProcess)
return lpCreationTime
}
It's a partial response. It should be possible to analyze and handle the command lines of all running processes in a similar way.
AHK can be sensitive to the order of execution in certain cases, so the script may need to be rerun based on when it was originally executed.
How do I get the command line of another process?
Last edited by Seven0528 on 03 Nov 2023, 00:01, edited 2 times in total.
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Script's main title is missing path - any ideas why?
Hello Seven (of Nine?),
thank you for your valuable input.
This looks interesting of another day.
Fortunately, I was able to successfully solve my issue meanwhile.
Regards, me.
thank you for your valuable input.
This looks interesting of another day.
Fortunately, I was able to successfully solve my issue meanwhile.
Regards, me.