-1

I'm using Delphi 5 running on Windows 7. An old application we want to update now has issues with UAC. We are able to get around it by changing the EnableLUA setting in the registry, but that's NOT an ideal solution. I'm trying to elevate it and found a lot of information online about how to do so. Before messing with the program, I created a very simple new program called InstallTester to use to figure out the process I need to use to fix this. Then I created a manifest called InstallTester.manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="InstallTester" version="1.0.0.0" processorArchitecture="x86"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <!-- Windows Vista application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--Windows 7-->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--Windows Vista-->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
    </application>
  </compatibility>
</assembly>

Then I created the .rc file (called Carrie.rc; at first I tried to call it InstallTester.rc, but I got a Duplicate Resources error, so I changed it) to include the manifest:

1 24 "InstallTester.manifest"

Then I compiled the .rc file using brcc32.exe, which created a .res file. Then I added the line to include the .res file in the app.dpr:

{$R 'Carrie.res'}

Then I built the project. And now when I run it (outside the IDE; inside the IDE I get the error saying it requires elevation), I don't get a Windows window asking if I give any permission. Instead I get the application, plus a window that looks like a command prompt window, but without any text. It has a cursor, but I can't type anything in it:

Screen shot of both windows

Just in case it's helpful, here's the full code:

program InstallTester;

{$R *.res}
{$R 'Carrie.res'}

uses
  Forms,
  InstallTest in 'InstallTest.pas' {Form1};

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

unit InstallTest;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlg( 'Thanks!', mtInformation, [mbOK], 000 );
end;

end.

Does anyone have a solution?

Keila
  • 113
  • 6

1 Answers1

2

This issue has nothing to do with your manifest. The ONLY way you could be getting that black window is if your EXE is compiled as a Console App instead of a VCL GUI app. A Console App has access to the Win32 API and thus can display GUI windows, but it still requires a console window, too. Double-check your project, make sure you created a VCL Forms Application to begin with and not a Console Application.

On a side note: your manifest is specifying a dependency on ComCtrl32 v6.0 to enable Visual Styles. Delphi 5 predates the introduction of Visual Styles, and there are quite a few bugs in the VCL that surface when Visual Styles are enabled. Some of which are fixed by using the Soft-Gems XP Theme Manager component in your project (which was eventually incorporated directly into the VCL in a later Delphi version). Otherwise, you should remove the dependency on ComCtrls32 v6.0 from your manifest, as you don't need it for UAC support.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Ugh...sure enough -- when I looked at the project options, Generate console application was checked; not sure how that happened; I just did a new application, not a new console application. Thank you, and thank you also for the info about ComCtrls32 v6.0. To disable that, do I just take out that whole ..<\dependency> section? – Keila May 15 '18 at 19:34
  • @Keila yes, just remove the `` section. You might also consider taking out the `` section, too, since Delphi 5 predates Windows XP so it doesn't actually have native compatibility with the OS versions that you listed, unless you have taken extra steps to design/test your code to ensure it is actually [compatible with those OS versions](https://msdn.microsoft.com/en-us/windows/compatibility/application-executable-manifest). – Remy Lebeau May 15 '18 at 19:37
  • Now when I try to run this program, Delphi hangs - Delphi has "Not Responding" show up at the top. I can compile & build just fine. This test program & the program I was working on for which I created the test program both exhibit this behavior, but other programs run fine from the IDE. The only thing I can think of that I might have done since the last time the programs ran fine from the IDE is install the youseful package. I tried unchecking it in the program options packages list; same result. I tried removing that package completely; same result. (I followed your suggestions above.) – Keila May 22 '18 at 15:58
  • Never mind; apparently that's what happens when I don't run Delphi in administrator mode with those programs. – Keila May 22 '18 at 16:58