Setting the Properties included in the app.manifest at compile time - c#

I have the following manifest in one project of mine (created on Visual Studio 2013, on C#).
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="5.4.0.5" name="Device"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><requestedExecutionLevel level="highestAvailable" uiAccess="false" /></requestedPrivileges></security></trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application></application></compatibility>
</asmv1:assembly>
The "assemblyIdentity" tag contains the project name and version; is there a way to mark this properties with a code to get both values from the project at compiler time, instead of changing it on the file?

Just to close this with something i found and solved my need, at MSDN's page they show how to Specify Build Events (C#) and use as an example a Build Event to change App Manifest.

Related

What does the default WPF app manifest look like?

we have a WPF application that currently uses the default manifest setting: "Embed manifest with default settings" and it works for us. We now need to add a custom manifest in order to use a third-party library that requires a setting in there. But we don't want to risk there being any other differences from before. And that brings the question. Is there a way to know what that default manifest that we are using now actually looks like so we can add to it? I have checked the obj and bin folders but didn't find anything in there and internet search hasn't really brought up much.
Thanks
The default manifest that is embedded into the assembly when you build the app looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="YourAppName.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
You can extract it using a decompiler.

Manifest does not work in VS2015

I'm trying to allow my program to write to the HKLM Keys. In order to achieve that I tried to create a manifest file:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</assembly>
But even with this file I'm still getting an exception:
"System.UnauthorizedAccessException" in mscorlib.dll
Cannot write to the registry key.
I'm using VS2015. I click create new element then pick Manifest file. Set the name to MyProgram.exe.manifest. Then in Project properties I select the proper manifest. And finally I'm changing execution level in Manifest file to requireAdministrator and rebuild the program.
But when I'm executing the MyProgram.exe it never shows that UAC window and when I try to write to HKLM in throws an exception. So I suspect the manifest is not working properly.
Please advise.
Thank you!!
You can do like this:
using administrator run program.
No permission to set permissions.

Visual Studio 2010 Setup Project marks application as requiring elevation

EDIT: I would still like an answer to this question if anyone can provide one, however I have decided to split out the non-administrative part of this project into another project which will call this project as required.
I have a project which manipulates some registry keys under HKLM - which obviously requires elevation. The application knows when it needs this elevation and will re-launch itself with runas to get elevation.
In the development environment this works fine, and the application also runs fine on intended targets in this form.
When I pump the project through a VS2010 setup project and install the project on the target system, the EXE gets marked as requiring elevation and requests it whenever it gets run before the application logic determines if it needs it.
I have searched for an hour or so and found nothing which relates, though I suspect the power of my search terms is insufficiently strong (or I lack the right ones) to find an appropriate result.
How can I stop the setup project from marking the executable as requiring elevation?
Subsequent to the comment below I added a custom manifest to the project with the same result, the manifest looked right to me:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>
Here's the output of the project's build (in the obj folder since that's what's being pulled in by the setup project):
http://i.stack.imgur.com/elrQh.png
The outwardly obvious thing is the lack of the UAC shield on the executable. After building the setup project, then installing it via the resultant MSI, the installed executable is like this:
http://i.stack.imgur.com/A33qz.png
Noting the now existing UAC shield.
Before adding the custom manifest, it was set to use a default one (which I suspect has the same content).

Cannot read files from install directory

I have a wpf application which reads from .xaml files to dynamically create views. However, when installed on a non-dev machine, the program says that the program has unauthorized access to the path where the files are stored. We are using relative pathing to read the files. Any suggestions?
Only way you'll have granted access to that Program Files folder is Creating and Embedding an Application Manifest (UAC).
As an example:
Executable: IsUserAdmin.exe
Manifest:IsUserAdmin.exe.manifest
Sample application manifest file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="IsUserAdmin"
type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
But you definitively must go and read the API.

Registration Free COM Interop: The application has failed to start because its side-by-side configuration is incorrect

Background. I've got a COM Wrapper assembly called ComWrapper.dll written in C#, and Visual Basic 6 application called Project1.exe. I've added the Project1.exe.manifest file (contents of which are shown below), and I'm getting an error that says "the application has failed to start because its side-by-side configuration is incorrect. Here's my configuration.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32"
name="Project1.exe"
version="1.0.0.0"
processorArchitecture="x86" />
<dependency>
<dependentAssembly>
<assemblyIdentity name="ComWrapper" version="1.0.0.0" processorArchitecture="msil"></assemblyIdentity>
<clrClass clsid="{3ac3d04e-1f83-4a27-b516-95e38126685d}" progid="MyComObjectNamespace.myclass" threadingModel="Both" name="MyComObjectNamespace.myclass" runtimeVersion=""></clrClass>
<file name="ComWrapper.dll" hashalg="SHA1"></file>
<dependency>
<dependentAssembly>
<assemblyIdentity name="mscorlib" version="2.0.0.0" publicKeyToken="b77a5c561934e089"></assemblyIdentity>
</dependentAssembly>
</dependency>
</dependentAssembly>
</dependency>
</assembly>
Any help would be much appreciated.
You need to use sxstrace.exe to determine the actual cause of the error, as the (complete) error message text tells you to do. Here's what it is wrong:
INFO: Parsing Manifest File
C:\Temp\sxs\Project1.exe.Manifest.
INFO: Manifest Definition Identity is Project1.exe,processorArchitecture="x86",type="win32",version="1.0.0.0".
INFO: Reference: ComWrapper,processorArchitecture="msil",version="1.0.0.0"
ERROR: Line 9: The element clrClass appears as a child of element urn:schemas-microsoft-com:asm.v1^dependentAssembly which is not supported by this version of Windows.
The problem is that dependentAssembly element should not provide a complete description of the assembly - it's only used to indicate a reference. You have to provide a separate component manifest file for that assembly, which then describes exported COM classes via clrClass. This is described in more detail in this MSDN article.
This error could be due to a typo in the config file.
Check your app.config file and look for typos.

Categories