Replicating Run Box abilities Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Replicating Run Box abilities

21 Feb 2019, 21:21

How can I use autohotkey to run msconfig (for example) without knowing the full path?
Windows RUN box can do this, and so can the cmd box, but authotkey's "run" command just gives an error.

Is there some autohotkey setting, or am I stuck using a hidden comspec to run commands like msconfig?

I've tried this, but it doesn't work either. But I can run msconfig from the Windows run box.

Code: Select all

run, %comspec% /c msconfig,,hide
I want to be able to run anything that I could from the RUN box.

I've tried this, too; the cmd box flashes and disappears

Code: Select all

HiddenConsoleCommand(whatcommand) {
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec(ComSpec . " /d c:\windows\system32 /C " . whatcommand)
    return exec.StdOut.ReadAll()
}
I'm using an admin account. I can launch it from the RUN box, and from the CMD window, but not from ahk, even with its full path.
AutoHotkey 1.1.30.01 Unicode on Windows 7 Pro x64

I found this, but is this a good way?
Last edited by BGM on 21 Feb 2019, 22:29, edited 3 times in total.
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 22:17

If you can run it via cmd.exe, you can use the built-in ComSpec variable which holds the path to it. This works for me:

Code: Select all

Run %ComSpec% /c "msconfig", , hide
But this works, too, on my system:

Code: Select all

run msconfig.exe
Even run msconfig works here in my Win10, probably because of the setting of the PATH system variable on this computer.
Last edited by gregster on 21 Feb 2019, 22:20, edited 1 time in total.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 22:20

No, on my Windows7, if I do

Code: Select all

run msconfig.exe
;or
run, c:\windows\system32\msconfig.exe   <--this is the full path; ahk cannot run it because it cannot see it

I get ahk's can't find file message.
But, like I said, it works in my RUN box.
Last edited by BGM on 21 Feb 2019, 22:25, edited 2 times in total.
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 22:21

Probably because of the setting of the PATH system variable. It specifies a set of directories where executable programs are located.

But then again, the full path should work anyway (it does here).
Last edited by gregster on 21 Feb 2019, 22:24, edited 1 time in total.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 22:23

If c:\windows\system32 was not in my PATH, then I couldn't run it from a cmd box; but I can. I just can't seem to do it from ahk.
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 22:28

Are you running 32 bit AHK on a 64 bit Windows? Then, Lexikos solution explanation is probably what is going on here.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 22:29

AutoHotkey 1.1.30.01 Unicode on Windows 7 Pro x64
I'm running 32 bit autohotkey. But that shouldn't matter, should it?
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 22:32

okay, if I run it with 64 bit autohotkey, *THEN* it runs msconfig with no problem.
aaaaahhhhhggggghhhhh
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 22:33

I matters. Look at the docs of A_ProgramFiles. There, it matters, too:
The Program Files directory (e.g. C:\Program Files or C:\Program Files (x86)). This is usually the same as the ProgramFiles environment variable.

On 64-bit systems (and not 32-bit systems), the following applies:

If the executable (EXE) that is running the script is 32-bit, A_ProgramFiles returns the path of the "Program Files (x86)" directory.
For 32-bit processes, the ProgramW6432 environment variable contains the path of the 64-bit Program Files directory. On Windows 7 and later, it is also set for 64-bit processes.
The ProgramFiles(x86) environment variable contains the path of the 32-bit Program Files directory.
That's why Lexikos recommends to de-activate the redirection...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Replicating Run Box abilities  Topic is solved

21 Feb 2019, 22:34

I tested on Windows 7 64-bit.
This works on AHK 64-bit:

Code: Select all

Run, msconfig
This works on AHK 64-bit and 32-bit:

Code: Select all

DllCall("kernel32\Wow64DisableWow64FsRedirection", PtrP,0)
Run, msconfig
Cheers.

@gregster, by 'Lexikos solution explanation' do you mean that A_ProgramFiles quote?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 22:41

Thanks, jees and greg
It *does* work with the dllcall in 32bit ahk. and it does work without it in 64bit ahk.
Does that work for the entire script? Or do I need to call it before each run command?
And do I need to re-enable that redirection for the system? Does it affect the entire system or only my script?

Maybe I should start thinking about compiling my scripts in 64bit.
If I want to compile as 64 bit, how do I tell ahk2exe to do that? or can I?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Replicating Run Box abilities

21 Feb 2019, 22:44

I use Wow64DisableWow64FsRedirection once per script, it only affects the script.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 22:48

BGM wrote:
21 Feb 2019, 22:41
Maybe I should start thinking about compiling my scripts in 64bit.
If I want to compile as 64 bit, how do I tell ahk2exe to do that? or can I?
In ahk2exe you can choose a different base file (.bin) for compilation, afaik. It should offer 32 bit ANSI and Unicode, and 64 bit Unicode.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 22:52

gregster - yes, I saw that in the docs - if I use the 64bit bin file, will the compiler know to create a 64 bit application? That was my hangup, actually.
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 22:54

As I understand it, yes - but I compile only once a year (in a busy year). So, I am no expert... :)
And 64 bit AHK should compile in 64 bit by default.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Replicating Run Box abilities

21 Feb 2019, 23:01

The docs say that the ahk2exe doesn't even use autohotkey.exe. I guess that's why you need the 64bit bin file, maybe?
gregster
Posts: 9021
Joined: 30 Sep 2013, 06:48

Re: Replicating Run Box abilities

21 Feb 2019, 23:02

The bin file is already included in the folder... it is (more or less) the same as the exe but ready for compilation/combination with the text-based ahk-file.

I just tried it and compiled a 32-bit Unicode AHK-exe-file by selecting the right bin file, while having installed 64 bit AHK. (By default, it creates a 64 bit exe.)
This line can help determine what version the current script or exe is running on (for testing).

Code: Select all

 Msgbox % "v" A_AhkVersion " " (A_PtrSize = 4 ? 32 : 64) "-bit " (A_IsUnicode ? "Unicode" : "ANSI")

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jeves, mikeyww, Thorlian and 281 guests