Need help with VBS using AutoHotkey.dll Topic is solved

Ask for help, how to use AHK_H, etc.
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Need help with VBS using AutoHotkey.dll

Post by burque505 » 01 Jul 2021, 10:44

Hi all,
I have found very few (make that zero) examples of using VBScript with recent AutoHotkey.dll.
This, for example, doesn't work:

Code: Select all

set AhkCom = CreateObject("AutoHotkey.Script")
AhkCom.ahktextdll("MsgBox Hello World!")
It throws no errors, but just flickers and exits. I'm thinking it must need a statement like the 'While' loop in this working AHK code

Code: Select all

AhkCom := ComObjCreate("AutoHotkey.Script")
AhkCom.ahktextdll("MsgBox Hello World!")
While AhkCom.ahkReady()
Sleep, 100
MsgBox Exiting now
but I haven't had any luck with that in VBS. I've tried this:

Code: Select all

set AhkCom = CreateObject("AutoHotkey.Script")
While AhkCom.ahkready()
    WScript.Sleep(100)
Wend
AhkCom.ahktextdll("MsgBox 'Hello World!'")
but no luck.
Many thanks in advance!
Regards,
burque505

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Need help with VBS using AutoHotkey.dll

Post by HotKeyIt » 01 Jul 2021, 10:57

Try:

Code: Select all

set AhkCom = CreateObject("AutoHotkey.Script")
AhkCom.ahktextdll("MsgBox 'Hello World!'")
While AhkCom.ahkready()
    WScript.Sleep(100)
Wend

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Need help with VBS using AutoHotkey.dll

Post by burque505 » 01 Jul 2021, 11:10

@HotKeyIt, thanks, I had tried that as well. Just tried again - it flickers but no MessageBox. Did it work for you? I'm on an old Win7 box, so maybe that's it. EDIT - tried on Win10, same result - flickers, no error, no MsgBox.
Regards,
burque505

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Need help with VBS using AutoHotkey.dll

Post by HotKeyIt » 01 Jul 2021, 14:11

Works fine for me, did you register 64 and 32 dll, also note you have to run regsvr32 as admin to register the dll.
E.g. start cmd as admin and run regsvr32 "C:\Scratch\Program Files\AutoHotkey\x64w\AutoHotkey.dll"

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Need help with VBS using AutoHotkey.dll

Post by burque505 » 01 Jul 2021, 15:16

@HotKeyIt, that certainly helped!

I had had both registered for years, which is what I don't understand. All the AHK_L scripts that I had calling AutoHotkey.dll were working fine.
But I downloaded the latest versions of AutoHotkey.dll and re-registered them.
On Win10 and win7 both I have to run "C:\windows\SysWOW64\wscript myscript.vbs", just running "wscript myscript.vbs" throws no errors but flickers, but that's a minor inconvenience to be sure. Thanks again.

Regards,
burque505

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Need help with VBS using AutoHotkey.dll

Post by burque505 » 02 Jul 2021, 07:20

As a follow up, I feel my Windows Script Host is probably really misconfigured. In the registry the default for HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command is set to

Code: Select all

"%SystemRoot%\System32\WScript.exe" "%1" %*
and HKEY_CLASSES_ROOT\VBSFile\Shell\Open2\Command is set, as you might expect, to

Code: Select all

"%SystemRoot%\System32\CScript.exe" "%1" %*
in the registry.

On my system the 32-bit AutoHotkey.dll seems to be working from VBS, only if I call it with the SysWOW64 wscript or cscript. (I'm assuming the 32-bit version of cscript can't call the 64-bit AHK DLL.) But using the System32 cscript yields this:

Code: Select all

[Window Title]
Microsoft ® Console Based Script Host

[Main Instruction]
Microsoft ® Console Based Script Host has stopped working

[Content]
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.

[Debug] [Close program]
This script runs fine with AHK_L 32-bit and AHK_L 64-bit, so I'm assuming my AutoHotkey DLLs are both registered:

Code: Select all

ahk:=ComObjCreate("Autohotkey.Script")

ahk.ahktextdll("")
Sleep 100
ahk.addScript("Func(a="""",b=""""){`nMsgBox % a ""``n"" b`n}")
ahk.ahkFunction("func","test1", "test2")
MsgBox Ende
but apparently I'm not getting the 64-bit dll to run with CScript or VBScript.

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Need help with VBS using AutoHotkey.dll

Post by HotKeyIt » 02 Jul 2021, 08:03

Try

Code: Select all

set AhkCom = CreateObject("AutoHotkey.Script.X64")
AhkCom.ahktextdll("MsgBox 'Hello World!'")
While AhkCom.ahkready()
    WScript.Sleep(100)
Wend

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Need help with VBS using AutoHotkey.dll

Post by burque505 » 02 Jul 2021, 08:11

Crashed in both cscript and wscript, this works so I'm pretty sure the DLLs are registered:

Code: Select all

ahk:=ComObjCreate("Autohotkey.Script.x64")

ahk.ahktextdll("")
Sleep 100
ahk.addScript("Func(a="""",b=""""){`nMsgBox % a ""``n"" b`n}")
ahk.ahkFunction("func","test1", "test2")
MsgBox Ende
I really appreciate you taking the time to help, by the way.

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Need help with VBS using AutoHotkey.dll

Post by HotKeyIt » 02 Jul 2021, 10:55

For 32-bit you should use:

Code: Select all

Set AhkCom = CreateObject("AutoHotkey.Script.UNICODE")
AhkCom.ahktextdll ("MsgBox 'Hello World!'")
While AhkCom.ahkready()
    WScript.Sleep (100)
Wend

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Need help with VBS using AutoHotkey.dll

Post by burque505 » 02 Jul 2021, 12:38

Thanks, that works, but with 32-bit it also works just as

Code: Select all

Set AhkCom = CreateObject("AutoHotkey.Script")
. The 64-bit VBS scripts don't run on either my Win10 machine (well, they flicker and die) or my Win7 machine.
The Win7 machine has other problems, though - %windir%\SysWOW64\regsvr32.exe scrrun.dll doesn't write to the registry, and I can't even modify the values manually from regedit (get a message that the values can't be written). So that's certainly not going to help. Everything under [code]HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}[/code] has no value set and no value can be set, not even from safe mode. Until I fix that (if I can) I'll give up on the win7 machine. Registry fixed, same problems on Win7.

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Need help with VBS using AutoHotkey.dll  Topic is solved

Post by HotKeyIt » 02 Jul 2021, 16:08

This works fine for me with C:\Windows\System32\cscript.exe C:\ahk.vbs

Code: Select all

Set AhkCom = CreateObject("AutoHotkey.Script.X64")
AhkCom.ahktextdll ("MsgBox 'Hello World!'")
While AhkCom.ahkready()
    WScript.Sleep (100)
Wend

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Need help with VBS using AutoHotkey.dll

Post by burque505 » 02 Jul 2021, 16:18

:( And for me it doesn't. Just the 32-bit cscript works (without the .x64, of course).
Same result on Win10 and Win7.
Wonder if I should try a different pair of AutoHotkey.dlls? Which would you recommend? I'd be happy to try whatever you're using. :D
EDIT: I downloaded the latest releases, unregistered and re-registered everything. Sigh of relief - everything works.
Thanks for your patience, @HotKeyIt!

Post Reply

Return to “Ask for Help”