Recent

Author Topic: runtime Error 740  (Read 5705 times)

cpicanco

  • Sr. Member
  • ****
  • Posts: 476
  • Programmer and Behavioral Scientist
    • Portfolio
runtime Error 740
« on: December 17, 2016, 03:37:44 pm »
On windows 10, after succefully compiling a program, the debugger exits with a runtime error 740.

There is an error message that reads "Error 740: The requested operation requires elevation", but this message was not shown, only the number was shown. 

Running the program outside Lazarus gives the error message : "A referral was returned from the server".

Just right clicking and selecting Open as admin does not work. 

I solved the problem by right clicking at the executable, selecting properties and checking the box "Run as administrator". In Lazarus, project options, the item "Require administrator" was selected in the "Execution level" combo box. Error 740 persists when "as invoker" item was selected. Error 740 persists when running Lazarus as admin (just by right clicking and selecting open as admin, no checkbox...).

I am guessing that I am missing something here because the program does not requires admin privilegies. It requires only network access (libzmq.dll, with 14.0 vs toolkit, is a dependency).

So how to properly solve this issue?

Thaddy

  • Hero Member
  • *****
  • Posts: 12988
Re: runtime Error 740
« Reply #1 on: December 17, 2016, 04:53:58 pm »
You need to define a rule for the windows firewall.
I actually get compliments for being rude... (well, Dutch, but that is the same)

cpicanco

  • Sr. Member
  • ****
  • Posts: 476
  • Programmer and Behavioral Scientist
    • Portfolio
Re: runtime Error 740
« Reply #2 on: December 17, 2016, 06:10:05 pm »
Yes, I did setup a firewall rule. Error 740 persists without checking the "run as admin" checkbox.

Thaddy

  • Hero Member
  • *****
  • Posts: 12988
Re: runtime Error 740
« Reply #3 on: December 18, 2016, 08:03:30 am »
Yes, I did setup a firewall rule. Error 740 persists without checking the "run as admin" checkbox.
In that case:
Did you include a manifest resource? In that you can request elevation.
https://msdn.microsoft.com/en-us/library/windows/desktop/dn481241(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374191(v=vs.85).aspx

If the user has sufficient rights on the network, then the privilege level should probably be "AsInvoker".
The application will then inherit the rights of the user.
« Last Edit: December 18, 2016, 12:15:57 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

cpicanco

  • Sr. Member
  • ****
  • Posts: 476
  • Programmer and Behavioral Scientist
    • Portfolio
Re: runtime Error 740
« Reply #4 on: December 22, 2016, 03:40:03 pm »
Hi Thaddy, many thanks for your time. Do you know if the project option "Include manifest file to enable themes" is the same manifest you poited out? It was checked and the error persists.

Badscales

  • Newbie
  • Posts: 1
Re: runtime Error 740
« Reply #5 on: January 11, 2023, 12:38:25 pm »
Error 740 came out of the blue to spoil my Lazarus experience this morning. It wouldn't go away...  Every time I tried to run the (splendid and magnificent!) software I had been testing and re-writing successfully for a couple of weeks I was told by Lazarus that the programme could not be made to run. In desperation,  I eventually tried double-clicking the newly-compiled version outside Lazarus. I found I had to confirm that I wanted to allow my software to make changes to the system before it would start my programme, which ran (beautifully and perfectly  - well, almost!) thereafter. To cut a long story short, I had to invent another user for my computer, make him/her/it an 'administrator' and demote myself from that exalted status.  Problem solved, and the solution might be worth trying, but no guarantees! 

Thaddy

  • Hero Member
  • *****
  • Posts: 12988
Re: runtime Error 740
« Reply #6 on: January 11, 2023, 02:11:15 pm »
Is absolutely wrong and very bad advice. I gave the correct answer above and many years ago (2016).
740 can only be caused by a missing or malformed manifest. All that is explained above,

Simply study how manifest resources work. No need for administrator rights.
so:
- A proper manifest file or resource (asInVoker, unless the application needs access to other user accounts, then and only then requireAdministrator - which is restricted to the application, not the user!)
- Optionally a firewall rule, usually unlikely. when asInvoker applies.

Additional remarks:
During debugging your own code you might use administrator rights, but not for distribution.
Depending on the application, it may be the case that the application is so intrusive or exposed it needs to be code signed.
The latter is unlikely in most normal cases.

And a very belated post script to cpicanco: That is indeed the same manifest file, but you already knew that!

Usually this example manifest is enough:
Code: XML  [Select][+][-]
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  3.   <assemblyIdentity
  4.    version="1.0.0.0"
  5.    processorArchitecture="*"
  6.    name="MyApp"
  7.    type="win32"
  8.  />
  9.   <description>My App</description>
  10.   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  11.     <security>
  12.       <requestedPrivileges>
  13.         <requestedExecutionLevel
  14.          level="asInvoker"
  15.          uiAccess="false" />
  16.       </requestedPrivileges>
  17.     </security>
  18.   </trustInfo>
  19. </assembly>
You may want to set uiAccess to true if applicable, usually not, along with the application name and the platform in the correct places.
Adapt an existing manifest file to include all of the application description part or simply replace or add the trust info part.

If your application has no manifest yet, the above should work immediately.
Simplest way to test: save the above as <your executable name>.manifest in the same directory as your executable.
If it works, compile it into a resource file and include the rc in your application. The resource constant is 24.
Note manifests are case sensitive, be aware of that.

A useful msdn entry is here: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests?redirectedfrom=MSDN
« Last Edit: January 17, 2023, 11:24:01 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

gfkat

  • Newbie
  • Posts: 1
Re: runtime Error 740
« Reply #7 on: January 17, 2023, 09:52:06 am »
In some case you just need to edit the configuration of the project and configure the execution level to AsInvoker, see attachment.

Thaddy

  • Hero Member
  • *****
  • Posts: 12988
Re: runtime Error 740
« Reply #8 on: January 17, 2023, 11:23:00 am »
In some case you just need to edit the configuration of the project and configure the execution level to AsInvoker, see attachment.
Correct.
I actually get compliments for being rude... (well, Dutch, but that is the same)

 

TinyPortal © 2005-2018