Page 1 of 1

DllCall("UpdateResource" ... but faster?

Posted: 23 May 2018, 01:49
by newbieforever
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

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

Posted: 25 May 2018, 01:06
by newbieforever
No idea?

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

Posted: 25 May 2018, 03:12
by just me
Why do you need it to be faster?

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

Posted: 25 May 2018, 03:30
by newbieforever
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" ...

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

Posted: 25 May 2018, 04:08
by just me
Looking at your recent questions related to AutoHotkeySC.bin, are you trying to replace the embedded script in an Ahk.exe?

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

Posted: 25 May 2018, 04:22
by newbieforever
Yes, just me, I am doing this already.

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

Posted: 25 May 2018, 04:32
by just me
May I ask why you think to need that?

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

Posted: 25 May 2018, 04:38
by newbieforever
Just me, I test ahk scripts from a CompiledScript.exe.

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

Posted: 25 May 2018, 04:49
by just me
Well, but why does 'testing scripts' require to be 'faster'? How long does it take to update the script resource?

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

Posted: 25 May 2018, 05:01
by newbieforever
AutoHotkey.exe runs a script in a second or less, updating resource takes e.g. 15 seconds.

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

Posted: 25 May 2018, 05:08
by just me
That's rather much time. I'll try to make some tests.

So long!

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

Posted: 25 May 2018, 07:43
by Flipeador
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).

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

Posted: 25 May 2018, 08:44
by just me
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?

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

Posted: 25 May 2018, 09:04
by newbieforever
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%
}

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

Posted: 25 May 2018, 09:14
by newbieforever
Maybe I should mention: UpdateRes() is writting a tmp file on disk during processing.

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

Posted: 25 May 2018, 11:17
by newbieforever
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.

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

Posted: 25 May 2018, 11:42
by Flipeador
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?

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

Posted: 25 May 2018, 18:04
by newbieforever
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.

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

Posted: 25 May 2018, 18:31
by Flipeador
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).

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

Posted: 25 May 2018, 22:30
by newbieforever
No other virus is detected. Compilation ends successfully. WD is updated.

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