VSoft Technologies BlogsVSoft Technologies Blogs - posts about our products and software development.https://www.finalbuilder.com/resources/blogsWindows Manifest Fileshttps://www.finalbuilder.com/resources/blogs/postid/753/windows-manifest-filesDelphi,FinalBuilder,XMLMon, 28 Aug 2017 12:35:00 GMT<p>In this post I'm going to look at Windows Manifest Files, what they do, why we need them and how to use them in Delphi and FinalBuilder.</p> <p>We often get asked questions about UAC prompts, High DPI settings, Windows Themes etc when compiling Delphi & C++Builder projects in FinalBuilder. In this post we'll dissect windows manifest files, and look at how the project settings in Rad Studio interact with the manifest file, and why you should use a custom manifest file.</p> <h3>What is a manifest file and what's it for?</h3> <p>A manifest is an xml file, which is typically embedded as a resource (it can be a separate file, but it's not a good practice and is not recommended) in your native windows executable (x86 or x64). This file has information that tells windows (vista or later) what parts of windows it supports, what permissions it needs (UAC), what common control dependencies it has (<a href="https://en.wikipedia.org/wiki/Side-by-side_assembly" target="_blank">Windows Side-by-Side loading</a>).</p> <p>Without a manifest resource, windows has no idea what permissions your application needs, and will not treat your application kindly. You will find things like common controls (file dialogs etc) look strange, attempts to write to files failing and other general misery. In fact your application may fail to run at all on some systems.</p> <p>Ok, so now we know we really need a manifest, what does that look like.</p> <pre class="brush:xml; toolbar:false;"> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"> <assemblyIdentity name="VSoftTechnologies.FinalBuilder" processorArchitecture="x86" version="8.0.0.0" type="win32" /> <description>FinalBuilder is a GUI-based build automation tool for Windows developers.</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="asInvoker" uiAccess="false" /> </requestedPrivileges> </security> </trustInfo> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> </application> </compatibility> </assembly> </pre> <p> </p> <p>The above example is actually the manifest file used in the FinalBuilder IDE. Lets break it down.</p> <p> </p> <h4>AssemblyIdentity</h4> <p>The assemblyIdentity tells windows about your application and what the system architecture requirements are. This should be unique. Note that the type, name and version attributes are required. Typically, the version field just has the major version info, I guess you could update it with the exact version each time, but I've never found the need to do that.</p> <h4>Description</h4> <p>The description field is pretty self explanatory.</p> <h4>Dependency</h4> <p>The dependency section is where you describe the side by side dll dependencies, which for Delphi/C++ Builder applications means windows common controls. This is pretty standard stuff, but it's important because without it, your application will have pretty strange looking file dialogs, if it loads at all.</p> <h4>TrustInfo</h4> <p>The trustinfo section is all about security, it tells windows what sort of permissions your application should be given. The requestedExecutionLevel level attribute has 3 possible values :</p> <ul> <li><strong>asInvoker</strong> - requesting no additional permissions. This level requires no additional trust prompts.</li> <li><strong>highestAvailable</strong> - requesting the highest permissions available to the parent process. When a standard user runs the application, it will behave the same as asInvoker, ie no UAC prompt. If an administrator runs the application, they will see a UAC prompt.</li> <li><strong>requireAdministrator</strong> - requesting full administrator permissions. All users will see a UAC prompt, standard users will be required to enter an administrator password.</li> </ul> <p> </p> <p>The uiAccess attribute Indicates whether the application requires access to protected user interface elements. Most of the time, this should be set to false. The typical use case for setting it to true is when creating remote desktop style application (like teamviewer etc). If you do set it to true, your application needs to be signed - see this post for code signing in FinalBuilder(<a href="/resources/blogs/code-signing-changes-for-2016">https://www.finalbuilder.com/resources/blogs/code-signing-changes-for-2016</a>).</p> <p> </p> <h4>High DPI support.</h4> <p>I'm not going go into to detail on this, it's a complex issue with major differences between windows versions, and limited High DPI support in Delphi. I will say, think very carefully before you enable this, High DPI support in Delphi depends very much on the version of delphi, and third party control support. Don't just enable High DPI support without serious testing. See the msdn doco link at the bottom of this post.</p> <h4>Compatibility</h4> <p>The compatibility section tells windows what versions of windows your application supports. It enables windows functionality in your application. Manifests without a compatibility section default to Windows Vista level functionality.</p> <p>One of the areas where the compatibility section is very important is detecting the windows version. On Windows 8.1 and 10, in applications that do not specify compatibility with them, GetVersion and GetVersionEx will return 6.2.0.0 for the windows version, rather than 6.3.* for Windows 8.1 and 10.0.* for Windows 10. So your application will think it's running on Windows 8 (or Server 2012) and quite possibly disable functionality.</p> <h4>Don't use Rad Studio's default or auto generated manifest!</h4> <p>I'll explain why in a minute, but first lets look at delphi's support for manifests. Delphi's manifest support differs quite a lot depending on which version of Delphi you are using. I don't have every version installed to check on.</p> <p>The earliest version I have installed at the moment is D2010, which just has a cryptically named check box :</p> <p style="text-align: center;"><img alt="" src="/blogimages/vincent/windows-manifest/d2010-enable-themes.png" /></p> <p>This option will include a default manifest in the projectname.res file. No options to change anything about that manifest. The manifest included is woefully inadequate.</p> <h5>Fast forward to XE7 :</h5> <p> </p> <p style="text-align: center;"><img alt="" src="/blogimages/vincent/windows-manifest/xe7-enable-themes.png" /></p> <p> </p> <p>Things got slightly better (not sure in which XE? version though) as you can now point Rad Studio at a custom manifest file (and you should!) to be included with your application. The default manifest included is still woefully inadequate.</p> <h5>Fast forward again, to Seattle:</h5> <p> </p> <p style="text-align: center;"><img alt="" src="/blogimages/vincent/windows-manifest/seattle-manifest-file.png" /></p> <p> </p> <p>Things look different again here, now you can set the badly named "Enable High DPI" and "Enable Administrator Privileges" options. I say badly named, because that's not what those options do. Checking "Enable High DPI" won't make your application support High DPI, it just tells windows it does (when really, it doesn't unless embarcadero fixed it while I wasn't looking). The same applies to the "Enable Administrator Privileges" - it won't give your application Administrator Privileges, it just tells windows your application needs them to run. Semantics shemantics... but I know this has confused many a developer.</p> <p>Note that the auto generated manifest uses a template, default_app.manifest, which lives in the bin folder, which is typically under program files, so you might need admin access to modify. It's probably a bad idea to modify it anyway, as it will result in a "works on my machine" moment. This template is different in Seattle and later, as it has some "variables" that get substituted by the IDE when building, this file can't be used when building with FinalBuilder as we have no way to get at those variables.</p> <p>The manifest included is slightly better than before, but still inadequate.</p> <p>Berlin & Tokyo manifest options are the same as Seattle, just some layout/styling changes. The auto generated manifests have the same limitations as Seattle.</p> <p>So I said earlier, "Don't use Rad Studio's default or auto generated manifest", and said that the auto generated manifests are inadequate, here's why : they are simply missing information.</p> <p>There's no assemblyIdentity element, which according to microsoft is required. There's no description element. The High DPI option just sets the dpiAware element to "True/PM", or not at all. You should use a manifest file that is specific to and reflects your application.</p> <p>For the versions of Rad Studio that support specifying a custom manifest file, just do that. For versions without custom manifest support, uncheck the "Enable runtime themes" option, and add a resource to your project that includes the manifest :</p> <p>Example manifest.rc</p> <pre class="brush:delphi; gutter:false; toolbar:false; "> 1 24 "E:\\Source\\app\\myapp.manifest" </pre> <h3>Using Manifests in FinalBuilder</h3> <p>FinalBuilder has had support for manifest files for a long time (2007, in FB 5), way before Delphi mentioned the word manifest! On the resource compiler tab of the Delphi and C++Builder actions, there is a field to specify the manifest file.</p> <p style="text-align: center;"><img alt="" src="/blogimages/vincent/windows-manifest/fb8-resource-tab.png" /></p> <p>That's all there is to it, FinalBuilder will add that manifest to the projectname.res file (along with the icon and version info).</p> <p>One last thing, don't forget to add your custom manifest file to your version control, it's source code after all.</p> <h4>References :</h4> <p><a href="https://msdn.microsoft.com/en-us/library/aa374191%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396">MSDN - Application Manifests</a></p> 753Windows Vista compatibilityhttps://www.finalbuilder.com/resources/blogs/postid/658/windows-vista-compatibilityFinalBuilderTue, 22 May 2007 19:00:00 GMT<p>Now that FinalBuilder 5.5 is out, I've posted a short article detailing some of the things to keep in mind when using FB with Windows Vista and User Account Control (UAC.) <br /> <br /> On a more techy subject, most developers are probably already well and truly up to speed with Vista integration by now, but here are a few resources that I found invaluable while getting a grip on the concepts of UAC, manifests, elevation, virtualization, and the elevation prompt.</p> <p>Happy Vista-ing!</p> <ul> <li><a href="http://technet.microsoft.com/en-us/windowsvista/aa906021.aspx">User Account Control Overview</a> at Microsoft TechNet. A good semi-technical (code-free) overview of  UAC.</li> <li><a href="http://blogs.msdn.com/cjacks/archive/2006/09/08/exploring-manifests-part-2-default-namespaces-and-uac-manifests-in-windows-vista.aspx">Evolving the Software Organism: Default Namespaces and UAC Manifests in Windows Vista</a>. Covers some gotchas when embedding a UAC manifest.</li> <li><a href="http://weblogs.asp.net/kennykerr/archive/2006/09/29/Windows-Vista-for-Developers-_1320_-Part-4-_1320_-User-Account-Control.aspx">Kenny Kerr's Windows Vista for Developers (Part 4)</a>. Great code summary of the two ways to request UAC elevation in Vista. Creating a process with an elevated token, or creating an elevated out-of-process COM object.</li> <li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=BA73B169-A648-49AF-BC5E-A2EEBB74C16B&displaylang=en">Windows Vista Application Development Requirements for User Account Control Compatibility</a>. 500-pound-gorilla Word document, covers everything you ever wanted to know (and then some.)</li> </ul> 658