DllCall("UpdateResource" ... but faster?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

DllCall("UpdateResource" ... but faster?

23 May 2018, 01:49

In my script I am using DllCall("UpdateResource" ... to replace a resource in an executable. This is doing fine, but it is not very fast, probably because the changes are written to disk in several steps.

Is there a way to make this faster? Or--a strange question: Is it possible to update a resource in a runnig executable?

EDIT: Later tests and discussion showed that the slowness is caused by Windows Defender, since two weeks or so!!! And WD is slowing down other AHK-associated operations too. New topic: https://autohotkey.com/boards/viewtopic.php?f=5&t=49615
Last edited by newbieforever on 26 May 2018, 03:24, edited 3 times in total.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 03:12

Why do you need it to be faster?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 03:30

Hi, just me! Because I have to use the new exe as soon as possible.
I tested now the time consumption of the updating-process steps. The only time consuming step is DllCall("EndUpdateResource" ...
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 04:08

Looking at your recent questions related to AutoHotkeySC.bin, are you trying to replace the embedded script in an Ahk.exe?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 04:22

Yes, just me, I am doing this already.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 04:32

May I ask why you think to need that?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 04:38

Just me, I test ahk scripts from a CompiledScript.exe.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 04:49

Well, but why does 'testing scripts' require to be 'faster'? How long does it take to update the script resource?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 05:01

AutoHotkey.exe runs a script in a second or less, updating resource takes e.g. 15 seconds.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 05:08

That's rather much time. I'll try to make some tests.

So long!
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 07:43

15 seconds? that is exaggerated/ridiculous. Can you show us your Script?. I've been playing changing many resources, images, icons, ... (I'm doing my own compiler) all at once, it has not taken more than a few milliseconds (on a HDD).
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 08:44

After some testing I confirm Flipeador's observations. The replacement of a ~4K AHK script needs only milliseconds here (on a SSD).

The compiler is calling UpdateResource() to add the script to the exe, too. Does it need several seconds to compile a script on your system?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 09:04

That's interesting!

Code: Select all

; FirstScript.exe is e.g. a simple script containing only
; RETURN
; and compiled with Unicode-32 AutoHotkeySC.bin.


; If I run the following script from AutoHotkey.exe,
; UpdateRes() takes about 3.5 s (SSD).


FirstScript  := A_ScriptDir . "\FirstScript.exe"
SecondScript := A_ScriptDir . "\SecondScript.exe" 
FileCopy, %FirstScript%, %SecondScript%
ScrString := "MsgBox SECOND SCRIPT"
UpdateRes(SecondScript, ScrString)
Run %SecondScript%

RETURN

UpdateRes(ExeFil, ScrStr)
{
   t0 := A_TickCount
   VarSetCapacity(BinScrStr, BinScrStr_Len := StrPut(ScrStr, "UTF-8") - 1)
   StrPut(ScrStr, &BinScrStr, "UTF-8")
   Module := DllCall("BeginUpdateResource", "str", ExeFil, "uint", 0, "ptr")
   If !Module
      MsgBox ERR MODULE
   If !DllCall("UpdateResource", "ptr", Module, "ptr", 10, "str", ">AHK WITH ICON<"
                , "ushort", 0x409, "ptr", &BinScrStr, "uint", BinScrStr_Len, "uint")
      MsgBox ERR UPDATE
   If !DllCall("EndUpdateResource", "ptr", Module, "uint", 0)
      MsgBox ERR ENDUPDATE
   t := A_TickCount - t0
   MsgBox TIME: %t%
}
Last edited by newbieforever on 25 May 2018, 09:17, edited 1 time in total.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 09:14

Maybe I should mention: UpdateRes() is writting a tmp file on disk during processing.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 11:17

just me & Flipeador, thank you very much for your help, I see now there must be something wrong with my system. I have to find out what.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 11:42

Maybe it's the antivirus... have you tried disabling it and running the script as Admin?...
Your Script seems fine... no idea... Does the compiler also take seconds?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 18:04

Yes, it is a Windows Defender problem!!!
And yes, the compiler takes seconds too!
Deactivating WD enables compiling and updating of resources in ms.
WD reports a Trojan:Win32/Fuery.B!cl during compiling (indicating tmp files in Temp dir).

This is an enormous shock to me ... Will the use of AHK scripts become unreliable?

But why there are no other user reporting this problem?

I am using Windows 10 Home 10.0.16299.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 18:31

Maybe I should mention: UpdateRes() is writting a tmp file on disk during processing.
I never really noticed this. I just confirmed it using FolderChangesView. Has created an RCX4676.tmp file in the same directory as the Script.
Yes, it is a Windows Defender problem!!!
Does it detect AutoHotkey.exe?.
WD reports a Trojan:Win32/Fuery.B!cl during compiling (indicating tmp files in Temp dir).
So... the compilation ends successfully or not?. Have you tried updating WD?.
I don't use any antivirus so I can't test it. (edit* I have MBAM Premium -i installed it not long ago- but it does not detect anything).
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: DllCall("UpdateResource" ... but faster?

25 May 2018, 22:30

No other virus is detected. Compilation ends successfully. WD is updated.

EDIT: New topic: https://autohotkey.com/boards/viewtopic.php?f=5&t=49615

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: marypoppins_1, mikeyww, Rohwedder, RussF and 133 guests