[Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Ross
Posts: 100
Joined: 13 Mar 2016, 00:27

[Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by Ross » 29 Sep 2019, 08:26

I followed this section here in order to enable AHK to successfully interact with programs that require administrator privileges, such as the Windows Task Manager. After updating to 1.1.31, it doesn't work anymore: scripts won't run, and will return a message like this:

Image

In order to run my scripts, I have to go to AutoHotkeyU64_UIA.exe's properties and set it to run only as administrator, which is inconvenient and less secure: for instance, drag-and-drop on regular apps won't work.

What should I do?

Edit: Running Windows 10 v.1903 18362.356.

Edit2: uninstalled and tried installing the previous (1.1.30.03) version, but this happened:

Image
Last edited by Ross on 03 Oct 2019, 22:13, edited 1 time in total.

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 29 Sep 2019, 19:39

You can try opening certmgr.msc and deleting the "AutoHotkey" certificate under Personal, then reinstall. EnableUIAccess (included in the installer) creates the certificate, but only if it doesn't already exist.

If that doesn't work, check the status of the digital signature under Digital Signatures tab on the file properties of the UIA.exe files.

I use UIA for my main scripts, and didn't have any issues.

User avatar
Ross
Posts: 100
Joined: 13 Mar 2016, 00:27

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by Ross » 30 Sep 2019, 00:04

Weird... in my certmgr, it didn't find anything AutoHotKey-related under the Personal section, but under the Trusted Root Authorities. Anyway, I removed it, uninstalled AHK 1.1.30.03 and installed the newest 1.1.31.01 version.

At first, I did not run the installer itself as administrator. I selected custom installation and followed all the way through until I could make sure I would check the "Add Run with UI access context menu" box. Still, I stumbled on the same second error message shown above for the three UIA files.

When checking those executables in the installation folder, I saw the "_UIA" files have the same byte size as their regular counterparts. Does it mean it didn't work? I guess so. And, under the properties for those files, I saw no "Digital Signatures" tab, only the five common ones (General, Compatibility, Security, Details, Previous Versions.)

So I uninstalled again in order to run the installer with admin privileges. But before reinstalling, I checked certmgr again, and there was no AutoHotKey-related item anywhere, neither under personal nor under Trusted Root Authorities. I asked myself "where the heck is the .cer file?" So I ran a system-wide search and found nothing, but I came across a weird AUTOHOTKEYU64_UIA.EXE-9AB18B91.pffile just created under C:\Windows\prefetch.

So, I reinstalled, this time running the installer with admin privileges. Same problem as before: could not create any of the _UIA executables. But they are there in the AHK installation folder:

Image

Again, same size as the regular counterparts. (The 'tamanho' column means 'size').

Now, something extra bizarre: look at the modification times on the last column. I just reinstalled the program, but it shows the modification date Sep 28 2019 08:30:03 AM, but it is now precisely Sep 30 2019, 01:58:45, like shown in the first file! Whiskey-Tango-Foxtrot!

Did I have to restart Windows after removing the certificate manually?

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 30 Sep 2019, 01:26

I see no reason that you should need to restart Windows, but also no reason not to try it.

The URL file is created anew by the installer, whereas the exe files are "existing" files that have come from my computer. I suppose they were compiled at Sep 28 2019 08:30:03 AM. My system shows ‎Saturday, ‎28 ‎September ‎2019, ‏‎9:30:03 PM (UTC+10). My UIA files show 10:18 PM, because that's when they were modified by EnableUIAccess (when I ran the install).

To debug this issue further, you will probably need to run EnableUIAccess manually. It's invoked by this code in the installer:

Code: Select all

        FileCopy AutoHotkey%A_LoopField%.exe, %file%, 1
        try
            EnableUIAccess(file)
        catch
            MsgBox 48, AutoHotkey Setup, Error creating %file%. ; Non-critical.
You can get the functions out of Installer.ahk (from EnableUIAccess, up to and including EnableUIAccess_Struct). I would remove the try-catch; just copy the exe file and call EnableUIAccess on the copy. Then maybe you'll see throw being called within EnableUIAccess, which might give us some clues.

The original script was on the old forum, but it could be a different version (or the links could be broken).

User avatar
Ross
Posts: 100
Joined: 13 Mar 2016, 00:27

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by Ross » 30 Sep 2019, 06:29

Wait wait, that looked advanced! Lets slow down a bit: it is the first time I ever open the Installer.ahk file. Actually, I haven't even noticed it before.
So, the portion you pasted above is at lines 1307 to 1311, and they're commented out. The non-commented part of that file ends in line 315.
The only 7 instances of "EnableUIAccess_Struct" in that file are all from lines 1446 and below, so I don't understand how you can mean "up and including".
Are you saying I should take the portion and uncomment, or lift until line 316 and push down the beginning of the commented part?
After that, I'm I supposed to just run Installer.ahk script? Because the only .exe files present are the AutoHotKey executables, the actual installer I used was AutoHotkey_1.1.31.00_setup.exe, which doesn't even reside in the installation folder (Program Files). What am I missing here? :crazy:

Edit: yes the Dropbox link inside that old forum post is expired :|

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 02 Oct 2019, 02:11

It is not commented out. I suppose that either you or your editor (syntax highlighting?) are interpreting the comment syntax incorrectly.

EnableUIAccess_Struct is a function. The last instance of this name in the file is the top of the function definition. You need everything up to and including the closing brace. The first line you do not need is InstallCompilerFiles() {.

My suggestion is to copy the portion I indicated into a new file, add a single call to EnableUIAccess("path of a copy of AutoHotkey.exe") (replacing the content of the string with the actual path, of course), and run it.

I assumed, perhaps wrongly, that you already know how to get code from the forums or some other source (a file in this case) and use them in a new script. The test is just to call EnableUIAccess() without any of the other installer code, but to do this you need the function definition and all functions it relies on.

teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by teadrinker » 02 Oct 2019, 10:32

@lexikos
Today tried to update AHK to 1.1.31.00 on Windows 10 and got the same issues.
In addition, my UIA files weren't updated:

Image
lexikos wrote: You can try opening certmgr.msc and deleting the "AutoHotkey" certificate under Personal, then reinstall.
Not found AutoHotkey in certmgr.msc.
lexikos wrote: To debug this issue further, you will probably need to run EnableUIAccess manually.
My code:

Code: Select all

EnableUIAccess("C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe")

EnableUIAccess(filename)
{
    hStore := DllCall("Crypt32\CertOpenStore", "ptr", 10 ; STORE_PROV_SYSTEM_W
        , "uint", 0, "ptr", 0, "uint", 0x20000 ; SYSTEM_STORE_LOCAL_MACHINE
        , "wstr", "Root", "ptr")
    if !hStore
        throw
    p := DllCall("Crypt32\CertFindCertificateInStore", "ptr", hStore
        , "uint", 0x10001 ; X509_ASN_ENCODING|PKCS_7_ASN_ENCODING
        , "uint", 0, "uint", 0x80007 ; FIND_SUBJECT_STR
        , "wstr", "AutoHotkey", "ptr", 0, "ptr")
    if p
        cert := new CertContext(p)
    else
        cert := EnableUIAccess_CreateCert("AutoHotkey", hStore)
    EnableUIAccess_SetManifest(filename)
    EnableUIAccess_SignFile(filename, cert, "AutoHotkey")
}
EnableUIAccess_SetManifest(file)
{
    xml := ComObjCreate("Msxml2.DOMDocument")
    xml.async := false
    xml.setProperty("SelectionLanguage", "XPath")
    xml.setProperty("SelectionNamespaces"
        , "xmlns:v1='urn:schemas-microsoft-com:asm.v1' "
        . "xmlns:v3='urn:schemas-microsoft-com:asm.v3'")
    if !xml.load("res://" file "/#24/#1") ; Load current manifest
        throw
    node := xml.selectSingleNode("/v1:assembly/v3:trustInfo/v3:security"
                    . "/v3:requestedPrivileges/v3:requestedExecutionLevel")
    if !node ; Not AutoHotkey v1.1?
        throw
    node.setAttribute("uiAccess", "true")
    xml := RTrim(xml.xml, "`r`n")
    VarSetCapacity(data, data_size := StrPut(xml, "utf-8") - 1)
    StrPut(xml, &data, "utf-8")
    if !(hupd := DllCall("BeginUpdateResource", "str", file, "int", false))
        throw
    r := DllCall("UpdateResource", "ptr", hupd, "ptr", 24, "ptr", 1
                    , "ushort", 1033, "ptr", &data, "uint", data_size)
    if !DllCall("EndUpdateResource", "ptr", hupd, "int", !r) && r
        throw
}
EnableUIAccess_CreateCert(CertName, hStore)
{
    if !DllCall("Advapi32\CryptAcquireContext", "ptr*", hProv
            , "str", CertName, "ptr", 0, "uint", 1, "uint", 8) ; PROV_RSA_FULL=1, CRYPT_NEWKEYSET=8
        throw
    prov := new CryptContext(hProv)
    if !DllCall("Advapi32\CryptGenKey", "ptr", hProv
            , "uint", 2, "uint", 0x4000001, "ptr*", hKey) ; AT_SIGNATURE=2, EXPORTABLE=..01
        throw
    key := new CryptKey(hKey)
    Loop 2
    {
        if A_Index = 1
            pbName := cbName := 0
        else
            VarSetCapacity(bName, cbName), pbName := &bName
        if !DllCall("Crypt32\CertStrToName", "uint", 1, "str", "CN=" CertName
            , "uint", 3, "ptr", 0, "ptr", pbName, "uint*", cbName, "ptr", 0) ; X509_ASN_ENCODING=1, CERT_X500_NAME_STR=3
            throw
    }
    VarSetCapacity(cnb, 2*A_PtrSize), NumPut(pbName, NumPut(cbName, cnb))
    VarSetCapacity(endTime, 16)
    DllCall("GetSystemTime", "ptr", &endTime)
    NumPut(NumGet(endTime, "ushort") + 10, endTime, "ushort") ; += 10 years
    if !hCert := DllCall("Crypt32\CertCreateSelfSignCertificate"
        , "ptr", hProv, "ptr", &cnb, "uint", 0, "ptr", 0
        , "ptr", 0, "ptr", 0, "ptr", &endTime, "ptr", 0, "ptr")
        throw
    cert := new CertContext(hCert)
    if !DllCall("Crypt32\CertAddCertificateContextToStore", "ptr", hStore
        , "ptr", hCert, "uint", 1, "ptr", 0) ; STORE_ADD_NEW=1
        throw
    return cert
}
class CryptContext {
    __New(p) {
        this.p := p
    }
    __Delete() {
        DllCall("Advapi32\CryptReleaseContext", "ptr", this.p, "uint", 0)
    }
}
class CertContext extends CryptContext {
    __Delete() {
        DllCall("Crypt32\CertFreeCertificateContext", "ptr", this.p)
    }
}
class CryptKey extends CryptContext {
    __Delete() {
        DllCall("Advapi32\CryptDestroyKey", "ptr", this.p)
    }
}
EnableUIAccess_SignFile(File, CertCtx, Name)
{
    VarSetCapacity(wfile, 2 * StrPut(File, "utf-16")), StrPut(File, &wfile, "utf-16")
    VarSetCapacity(wname, 2 * StrPut(Name, "utf-16")), StrPut(Name, &wname, "utf-16")
    cert_ptr := IsObject(CertCtx) ? CertCtx.p : CertCtx
    EnableUIAccess_Struct(file_info, "ptr", A_PtrSize*3 ; SIGNER_FILE_INFO
        , "ptr", &wfile)
    VarSetCapacity(dwIndex, 4, 0) ; DWORD
    EnableUIAccess_Struct(subject_info, "ptr", A_PtrSize*4 ; SIGNER_SUBJECT_INFO
        , "ptr", &dwIndex, "ptr", SIGNER_SUBJECT_FILE:=1, "ptr", &file_info)
    EnableUIAccess_Struct(cert_store_info, "ptr", A_PtrSize*4 ; SIGNER_CERT_STORE_INFO
        , "ptr", cert_ptr, "ptr", SIGNER_CERT_POLICY_CHAIN:=2)
    EnableUIAccess_Struct(cert_info, "uint", 8+A_PtrSize*2 ; SIGNER_CERT
        , "uint", SIGNER_CERT_STORE:=2, "ptr", &cert_store_info)
    EnableUIAccess_Struct(authcode_attr, "uint", 8+A_PtrSize*3 ; SIGNER_ATTR_AUTHCODE
        , "int", false, "ptr", true, "ptr", &wname)
    EnableUIAccess_Struct(sig_info, "uint", 8+A_PtrSize*4 ; SIGNER_SIGNATURE_INFO
        , "uint", CALG_SHA1:=0x8004, "ptr", SIGNER_AUTHCODE_ATTR:=1
        , "ptr", &authcode_attr)
    hr := DllCall("MSSign32\SignerSign"
        , "ptr", &subject_info, "ptr", &cert_info, "ptr", &sig_info
        , "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0, "uint")
    if (hr != 0)
        throw hr
}
EnableUIAccess_Struct(ByRef struct, arg*)
{
    VarSetCapacity(struct, arg[2], 0), p := &struct
    Loop % arg.Length()//2
        p := NumPut(arg[2], p+0, arg[1]), arg.RemoveAt(1, 2)
    return &struct
}
Error:
---------------------------
New15.ahk
---------------------------
Error: An exception was thrown.

Line#
001: EnableUIAccess("C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe")
004: {
005: hStore := DllCall("Crypt32\CertOpenStore", "ptr", 10, "uint", 0, "ptr", 0, "uint", 0x20000, "wstr", "Root", "ptr")
008: if !hStore
---> 009: Throw
010: p := DllCall("Crypt32\CertFindCertificateInStore", "ptr", hStore, "uint", 0x10001, "uint", 0, "uint", 0x80007, "wstr", "AutoHotkey", "ptr", 0, "ptr")
014: if p
015: cert := new CertContext(p)
016: Else
017: cert := EnableUIAccess_CreateCert("AutoHotkey", hStore)
018: EnableUIAccess_SetManifest(filename)
019: EnableUIAccess_SignFile(filename, cert, "AutoHotkey")

The current thread will exit.
---------------------------
ОК
---------------------------
What should I do now?

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 03 Oct 2019, 05:55

@teadrinker Change throw on line 9 (indicated in the error message) to throw A_LastError. This should show the reason for CertOpenStore failing.

teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by teadrinker » 03 Oct 2019, 08:20

@lexikos
Sorry, last time I launched the code without admin privileges. Now:
Error: Unhandled exception.

Specifically: 2148081670

Line#
106: EnableUIAccess_Struct(subject_info, "ptr", A_PtrSize*4, "ptr", &dwIndex, "ptr", SIGNER_SUBJECT_FILE:=1, "ptr", &file_info)
108: EnableUIAccess_Struct(cert_store_info, "ptr", A_PtrSize*4, "ptr", cert_ptr, "ptr", SIGNER_CERT_POLICY_CHAIN:=2)
110: EnableUIAccess_Struct(cert_info, "uint", 8+A_PtrSize*2, "uint", SIGNER_CERT_STORE:=2, "ptr", &cert_store_info)
112: EnableUIAccess_Struct(authcode_attr, "uint", 8+A_PtrSize*3, "int", false, "ptr", true, "ptr", &wname)
114: EnableUIAccess_Struct(sig_info, "uint", 8+A_PtrSize*4, "uint", CALG_SHA1:=0x8004, "ptr", SIGNER_AUTHCODE_ATTR:=1, "ptr", &authcode_attr)
117: hr := DllCall("MSSign32\SignerSign", "ptr", &subject_info, "ptr", &cert_info, "ptr", &sig_info, "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0, "uint")
120: if (hr != 0)
---> 121: Throw,hr
Tryed to remove these files manually, then repair. The error warnings:
  • Error creating AutoHotkeyA32_UIA.exe.
  • Error creating AutoHotkeyU32_UIA.exe.
  • Error creating AutoHotkeyU64_UIA.exe.
In addition, when I clicked «View Changes & New Feature» or «View the Tutorial» in the setup window, I got the messages «unable to open file».
However, the UIA files were updated to 1.1.31.0., but they still doesn't work, the code above returns the same error.

User avatar
Ross
Posts: 100
Joined: 13 Mar 2016, 00:27

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by Ross » 03 Oct 2019, 22:12

See I've been away for quite some time now? That's because I've bought a new SSD and made a fresh Windows install. Still configuring things, especially the annoying permissions for files residing in other hard drives.
The main thing, though, is: the simple fact that I made the fresh Windows install solved the problem! However, I really don't know what it was. But relax, I'll be back on this topic ASAP to read your inputs.
Thanks and see you later!

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 04 Oct 2019, 04:00

@teadrinker
Run this as administrator and then try reinstalling.

Code: Select all

MsgBox % "Certificate " (DeleteCertFromStore("Root", "AutoHotkey") ? "deleted" : "not found")

MsgBox % "Key container " (DeleteKeySet("AutoHotkey") ? "deleted" : "not deleted (" A_LastError ")")

DeleteKeySet(Name) {
	return DllCall("Advapi32\CryptAcquireContext", "ptr*", undefined
        , "str", Name, "ptr", 0, "uint", 1, "uint", 16) ; PROV_RSA_FULL=1, CRYPT_DELETEKEYSET=16
}

DeleteCertFromStore(Store, CertName) {
	if !hStore := DllCall("Crypt32\CertOpenStore", "ptr", 10 ; STORE_PROV_SYSTEM_W
        , "uint", 0, "ptr", 0, "uint", 0x20000 ; SYSTEM_STORE_LOCAL_MACHINE
        , "wstr", Store, "ptr")
		throw
	if !p := DllCall("Crypt32\CertFindCertificateInStore", "ptr", hStore
        , "uint", 0x10001 ; X509_ASN_ENCODING|PKCS_7_ASN_ENCODING
        , "uint", 0, "uint", 0x80007 ; FIND_SUBJECT_STR
        , "wstr", CertName, "ptr", 0, "ptr")
		return 0
	if !DllCall("Crypt32\CertDeleteCertificateFromStore", "ptr", p)
		throw
	return 1
}
I had certificates under "Personal" for the current user, from previous versions of the script. The certificate would actually be under "Trusted Root Certification Authorities" for the local computer, not the current user. If you run certmgr.msc, it will only show you the current user's certificates. In order to show the local computer's certificates, you need to run mmc.exe and add the Certificates snap-in. However, the code above will directly delete the certificate created by the installer, if present.

I have also found that deleting the certificate does not delete the associated private key. If you delete the certificate and not the private key, this will prevent the installer from working, as it will attempt to create the key and fail because it already exists.

teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by teadrinker » 04 Oct 2019, 04:51

lexikos wrote: I have also found that deleting the certificate does not delete the associated private key. If you delete the certificate and not the private key, this will prevent the installer from working, as it will attempt to create the key and fail because it already exists.
The code above showed me: Certificate deleted; Key container not deleted (-2146893802)
However, it seems that reinstalling solved the problem, now UIA files work.
teadrinker wrote: when I clicked «View Changes & New Feature» or «View the Tutorial» in the setup window, I got the messages «unable to open file».
This issue still exist.
Thank you!

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 04 Oct 2019, 05:11

It appears the private key was missing. That would probably be a result of it specifically being deleted. The installer does not create it unless it is also creating the certificate.

Since the help file has nothing to do with UIA, I suggest you start a new topic, and post more detail, such as the actual error message.

teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by teadrinker » 04 Oct 2019, 05:35

lexikos wrote: I suggest you start a new topic, and post more detail, such as the actual error message.
If this issue persists in the next version, I'll create the topic. The help file exists in my autohotkey folder, it works. Thanks!

DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by DRocks » 04 Oct 2019, 05:52

lexikos wrote:
29 Sep 2019, 19:39
I use UIA for my main scripts, and didn't have any issues.
Hi Lexikos,
Do you recall any examples you've posted about how you are using this in your scripts?
Or would you please point out what this UIA is most useful to you / in general?

I am using microsoft Accessibility right now with Acc.ahk to identify unaccessible controls within Windows.Forms Classes of a accounting software but Id like to know if it can be better with what you guys are using.
Meanwhile Ill read more on the topic, thanks in advance.

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by lexikos » 04 Oct 2019, 18:30

@DRocks
I think you've missed the purpose of this topic, and are confusing UIAccess with UI Automation.

DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by DRocks » 04 Oct 2019, 21:33

My bad sorry and thanks for clarification

william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by william_ahk » 22 Sep 2022, 21:59

@lexikos I tried installing the latest v2 (beta.9) today and encountered this issue as well:
278: DllCall("MSSign32\SignerSign" , "ptr", subject_info, "ptr", cert_info, "ptr", sig_info , "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0, "hresult")

After running the certificate cleansing script the problem is gone.

User avatar
Barney
Posts: 55
Joined: 28 May 2014, 20:03
Location: Germany

Re: [Semi-Solved] Problem with AutoHotkeyU64_UIA.exe after version 1.1.31.00

Post by Barney » 02 Apr 2023, 02:56

I had the same problem as the OP. I think my certificate expired. IMO the expiration date should be set higher. Running the cleaning script helped. I'm using 1.1.28.00 and the expiration time seems to be 10 years.

Post Reply

Return to “Ask for Help (v1)”