* * *

Author Topic: "Program may need admin permissions"  (Read 2868 times)

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 636
    • Burdjia
"Program may need admin permissions"
« on: January 11, 2017, 01:56:02 pm »
Actually I'm not sure it is a problem with FPC but I need to find the culprit.

I've found some programs I made works perfectly on Windows 7 64bit, but when I close them a window appear saying that "This program may need administrator privileges."* allowing me to restart the application as administrator or label that program with a "This program works perfectly".

AFAIK the programs are compiled with FPC 3.0.0 as 32bit (I tried to build 64bit applications but it was impossible, is it?).  May be a newer compiler would fix this?  Or may be it is because they're running in 32bit?

May be the origin of the problem is the Allegro library I'm using?
_____________________________

* I'm Spanish so the message in English may be different than my translation.

Thaddy

  • Hero Member
  • *****
  • Posts: 4525
Re: "Program may need admin permissions"
« Reply #1 on: January 11, 2017, 02:00:38 pm »
No. Your problem is that you have to add a manifest resource.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 636
    • Burdjia
Re: "Program may need admin permissions"
« Reply #2 on: January 11, 2017, 02:04:22 pm »
That's new for me.  Is there a way to do it easily from command line (e.g. makefile)?  I should investigate.  Is there a wiki page or something?  A few searching doesn't find something useful (yet)...
« Last Edit: January 11, 2017, 02:05:56 pm by Ñuño_Martínez »

Thaddy

  • Hero Member
  • *****
  • Posts: 4525
Re: "Program may need admin permissions"
« Reply #3 on: January 11, 2017, 02:06:36 pm »
That's new for me.  Is there a way to do it easily from command line (e.g. makefile)?  I should investigate.  Is there a wiki page or something?  A few searching doesn't find something useful (yet)...
Windows 7 and up and forced on windows 10:
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="X86"
  6.        name="RoofGenius.RoofCalcWriter 10"
  7.        type="win32" />
  8.     <description>Executable</description>
  9.     <dependency>
  10.         <dependentAssembly>
  11.             <assemblyIdentity
  12.                type="win32"
  13.                name="Microsoft.Windows.Common-Controls"
  14.                version="6.0.0.0"
  15.                processorArchitecture="X86"
  16.                publicKeyToken="6595b64144ccf1df"
  17.                language="*" />
  18.         </dependentAssembly>
  19.     </dependency>
  20.     <!-- Identify the application security requirements. -->
  21.     <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
  22.       <ms_asmv2:security>
  23.         <ms_asmv2:requestedPrivileges>
  24.           <ms_asmv2:requestedExecutionLevel
  25.            level="asInvoker"
  26.            uiAccess="false"/>
  27.           </ms_asmv2:requestedPrivileges>
  28.          </ms_asmv2:security>
  29.     </ms_asmv2:trustInfo>
  30. </assembly>

See here for instructions:
http://stackoverflow.com/questions/14703013/adding-manifest-for-admin-rights-request
« Last Edit: January 11, 2017, 02:09:33 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

lainz

  • Hero Member
  • *****
  • Posts: 2001
Re: "Program may need admin permissions"
« Reply #4 on: January 11, 2017, 02:26:55 pm »
You must also add HighDPI stuff in the manifest if you don't want your visual (Allegro) application look blurry on HighDPI settings. And optional compatibility for each Windows OS.

manifest.xml

Code: XML  [Select]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  3.   <assemblyIdentity version="1.0.0.0" name="title" />
  4.   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
  5.     <security>
  6.       <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
  7.         <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
  8.       </requestedPrivileges>
  9.     </security>
  10.   </trustInfo>
  11.   <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  12.     <application>
  13.       <!-- Windows Vista -->
  14.       <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
  15.       <!-- Windows 7 -->
  16.       <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
  17.       <!-- Windows 8 -->
  18.       <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
  19.       <!-- Windows 8.1 -->
  20.       <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
  21.       <!-- Windows 10 -->
  22.       <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
  23.     </application>
  24.   </compatibility>
  25.   <application xmlns="urn:schemas-microsoft-com:asm.v3">
  26.     <windowsSettings>
  27.       <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
  28.     </windowsSettings>
  29.   </application>
  30.   <dependency>
  31.     <dependentAssembly>
  32.       <assemblyIdentity
  33.          type="win32"
  34.          name="Microsoft.Windows.Common-Controls"
  35.          version="6.0.0.0"
  36.          processorArchitecture="*"
  37.          publicKeyToken="6595b64144ccf1df"
  38.          language="*"
  39.        />
  40.     </dependentAssembly>
  41.   </dependency>
  42. </assembly>

manifest.rc

Code: Pascal  [Select]
  1. 1 24 "manifest.xml"

Thaddy

  • Hero Member
  • *****
  • Posts: 4525
Re: "Program may need admin permissions"
« Reply #5 on: January 11, 2017, 02:40:19 pm »
Tnx for the addition and I should have stressed forced for windows 10.X.. For newly installed software only, for some reason. It leaves existing programs to work after upgrading.
BTW: Your manifest should use AsInvoker..... That means that the application has the same rights as the user that started it. I
« Last Edit: January 11, 2017, 02:47:54 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 636
    • Burdjia
Re: "Program may need admin permissions"
« Reply #6 on: January 11, 2017, 04:54:59 pm »
Thank you.

After some testing (lainz manifest requests for administrator privileges when executing), I have this manifest:
Code: XML  [Select]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Windows manifest.
  3.  
  4.     Just as discussed at
  5.     http://forum.lazarus.freepascal.org/index.php/topic,35392.0.html
  6.     You should include this in ALL your Allegro applications.
  7.  -->
  8. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  9.     <assemblyIdentity
  10.       version="1.0.0.0"
  11.       processorArchitecture="X86"
  12.       name="RoofGenius.RoofCalcWriter 10"
  13.       type="win32" />
  14.     <description>Executable</description>
  15.     <dependency>
  16.         <dependentAssembly>
  17.             <assemblyIdentity
  18.               type="win32"
  19.               name="Microsoft.Windows.Common-Controls"
  20.               version="6.0.0.0"
  21.               processorArchitecture="X86"
  22.               publicKeyToken="6595b64144ccf1df"
  23.               language="*" />
  24.         </dependentAssembly>
  25.     </dependency>
  26. <!-- Identify the application security requirements. -->
  27.     <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
  28.       <ms_asmv2:security>
  29.         <ms_asmv2:requestedPrivileges>
  30.           <ms_asmv2:requestedExecutionLevel
  31.             level="asInvoker"
  32.             uiAccess="false"/>
  33.         </ms_asmv2:requestedPrivileges>
  34.       </ms_asmv2:security>
  35.     </ms_asmv2:trustInfo>
  36. <!-- OS compatibility. -->
  37.   <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  38.     <application>
  39.       <!-- Windows Vista -->
  40.       <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
  41.       <!-- Windows 7 -->
  42.       <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
  43.       <!-- Windows 8 -->
  44.       <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
  45.       <!-- Windows 8.1 -->
  46.       <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
  47.       <!-- Windows 10 -->
  48.       <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
  49.     </application>
  50.   </compatibility>
  51. <!-- HighDPI, so visuals don't look blurry on HighDPI settings. -->
  52.   <application xmlns="urn:schemas-microsoft-com:asm.v3">
  53.     <windowsSettings>
  54.       <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
  55.     </windowsSettings>
  56.   </application>
  57. </assembly

Anyway I should do a few more tests to be sure it works (i.e. Windows XP).  May be later I'll create a "Windows manifest" wiki page if nobody else does it.
« Last Edit: January 11, 2017, 04:57:26 pm by Ñuño_Martínez »

Thaddy

  • Hero Member
  • *****
  • Posts: 4525
Re: "Program may need admin permissions"
« Reply #7 on: January 11, 2017, 05:42:18 pm »
Don't ever use AsAdministrator unless you ARE the administrator or the user is intended to have administrator rights (which is global) ! Use AsInvoker. I can't shout out how important that is.

If the user is allowed to run your program (as invoker, which simply means he started it) it will run.
« Last Edit: January 11, 2017, 05:47:42 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

lainz

  • Hero Member
  • *****
  • Posts: 2001
Re: "Program may need admin permissions"
« Reply #8 on: January 11, 2017, 06:00:29 pm »
If that's the case, I understand it wrong the first time, I think that his application was needing administrator privileges, for that I changed that line. But if only was the error message, the lack of manifest, you do asInvoker.

lainz

  • Hero Member
  • *****
  • Posts: 2001
Re: "Program may need admin permissions"
« Reply #9 on: January 11, 2017, 06:13:38 pm »
Anyway I should do a few more tests to be sure it works (i.e. Windows XP).  May be later I'll create a "Windows manifest" wiki page if nobody else does it.

The thing is that you can enable the manifest from the Project Options already, even in command line applications.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 636
    • Burdjia
Re: "Program may need admin permissions"
« Reply #10 on: January 11, 2017, 08:34:16 pm »
I know, but I'm not using Lazarus here, just FPC and make.

So it looks fixed.  Thank you both.  :)

ASerge

  • Sr. Member
  • ****
  • Posts: 431
Re: "Program may need admin permissions"
« Reply #11 on: January 11, 2017, 09:32:12 pm »
I've found some programs I made works perfectly on Windows 7 64bit, but when I close them a window appear saying that "This program may need administrator privileges."* allowing me to restart the application as administrator or label that program with a "This program works perfectly".
"This program might require administrator privilege".
Windows treats a process as legacy if it’s 32-bit (versus 64-bit), is not running with administrative rights, and does not have a manifest file indicating that it was written for this version of Windows.
And your app is probably being detected as a setup. The Program Compatability Assistant is probably looking for changes of the sort an installer would make, and not seeing them, and is assuming that you were trying to run a setup that is rejecting the current version of windows or needs some sort of compatability fix to work.
As mentioned above, use the manifest.

lainz

  • Hero Member
  • *****
  • Posts: 2001
Re: "Program may need admin permissions"
« Reply #12 on: January 11, 2017, 09:48:05 pm »
I've found some programs I made works perfectly on Windows 7 64bit, but when I close them a window appear saying that "This program may need administrator privileges."* allowing me to restart the application as administrator or label that program with a "This program works perfectly".
"This program might require administrator privilege".
Windows treats a process as legacy if it’s 32-bit (versus 64-bit), is not running with administrative rights, and does not have a manifest file indicating that it was written for this version of Windows.
And your app is probably being detected as a setup. The Program Compatability Assistant is probably looking for changes of the sort an installer would make, and not seeing them, and is assuming that you were trying to run a setup that is rejecting the current version of windows or needs some sort of compatability fix to work.
As mentioned above, use the manifest.

Something like trying to write something in program files, accessing the registry..

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 636
    • Burdjia
Re: "Program may need admin permissions"
« Reply #13 on: January 12, 2017, 12:34:00 pm »
I've found some programs I made works perfectly on Windows 7 64bit, but when I close them a window appear saying that "This program may need administrator privileges."* allowing me to restart the application as administrator or label that program with a "This program works perfectly".
"This program might require administrator privilege".
Thanks for the fix and the comment. :)

ASerge

  • Sr. Member
  • ****
  • Posts: 431
Re: "Program may need admin permissions"
« Reply #14 on: January 12, 2017, 05:26:12 pm »
Something like trying to write something in program files, accessing the registry..
I think not in this case, because for legacy program used virtual storage. If you have such programs, then in %LOCALAPPDATA%\VirtualStore\ will be virtual "Program Files" and "Windows" for they.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus