is there a way to obtain the same result than set compiler flags at runtime for PEFlags?
Asked Answered
T

1

5

years ago i stumbled in the C0000006 external exception when running a large (100+MB) exe from a shared folder on some particular LANs. So I started using the compiler flags described in this question.

After years of succesful "execution of exe" on hundreds of customers in hundreds of networks i started having problems with the PE flags (somehow the exe was crashing at startup on same pcs and excluding one cause at a time i empirically found that commenting those flags was working).

Somehow the workaround i found is to build my exe twice (and let the customer choose which one to deploy), the first with these:

{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP}
{$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP} 

and the second commenting those.

This building overhead is annoying and I would like to avoid it. I do not think there is a way, but i ask for expert advice: is there a way to "activate those flags at runtime?" for example passing a command line parameter?

Another workaround i thought of is to copy locally the exe as the exe starts, so that it is always executed from the local machine, but I fear the scenarios i need to face, even if technically it is simple.

Thanks.

Transmute answered 3/10, 2018 at 7:27 Comment(0)
H
7

Is there a way to activate these flags at runtime, for example by passing a command line parameter?

No there is not. These PE flags are processed by the system loader, and the outcome is determined before any code in the executable is executed.

Another workaround I thought of is to copy locally the exe as the exe starts, so that it is always executed from the local machine.

That is precisely the effect that these PE flags have. If the executable file resides on a network volume, or a removable volume, then it is first copied to the swap file (a local file), and then executed.

Hoogh answered 3/10, 2018 at 7:37 Comment(6)
Thanks. What do you think of my workarounds? I ike the idea to copy the exe locally but i fear on some super-secure LANs this process will be blocked automatically.Transmute
I don't think that you have properly diagnosed the fault, or at least described it clearly. You say that the problem is resolved by building the executable twice. So, how can building it twice change the outcome? That makes little sense. Or do you supply both versions? Anyway, I answered the questions that you asked.Hoogh
Yes you are right, i mean bulding it twice and allow the customers with problems download the second one. This is acceptable since up to now the issue is on less than 2% of customers so i can handle it. I modified my question to specify this better.Transmute
Running executables from network volumes is flaky at best. Tell you clients not to do that and your problems will go away. That's what I do.Hoogh
I agree, but this oversimplifies upgrading: I just run DB scripts and replace an exe and the Client/Server is at the next release,and clients that use a link to an exe on a shared folder are already updated. The price for this is what you know better than me.Transmute
It's up to you how you tackle this, it's your problem after all. Anyway, I answered the two direct questions that you answered I think.Hoogh

© 2022 - 2024 — McMap. All rights reserved.