128

I have this code from a coworker (probably got it from the web somewhere) but he's out on vacation and I need to add this to the manifest file

<?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" />
    <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>
</asmv1:assembly>  

I am relatively new to this so any help would be appreciated. Thanks

I'm using Visual Studio 2010

davmos
  • 9,324
  • 4
  • 40
  • 43
Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177
  • 1
    possible duplicate of [How to force C# App to run as administrator on Windows 7](http://stackoverflow.com/questions/2818179/how-to-force-c-app-to-run-as-administrator-on-windows-7) – Hans Passant May 18 '11 at 20:39

6 Answers6

159

In Visual Studio 2010 and possibly in future versions you can add the manifest file to your project.

Right click on your project file on the Solution Explorer, select Add, then New item (or CTRL+SHIFT+A). There you can find Application Manifest File.

The file name is app.manifest. app manifest icon

If this item doesn't exist then your project type is not conform with a manifest file, e.g. web application.

shA.t
  • 16,580
  • 5
  • 54
  • 111
ibram
  • 4,414
  • 2
  • 22
  • 34
  • 1
    Thank you but I don't know how to create the file properly. – Cocoa Dev May 19 '11 at 13:22
  • Ibram's instructions also apply to Visual Studio 2012. – WorkSmarter Oct 31 '13 at 22:28
  • 2
    and Visual Studio 2013 as well. – buttercup Jul 12 '14 at 18:20
  • Cocoa, It creates a default manifest. You are able to change things in it (such as "program requires admin execution level") but you are free to keep it default – BlueWizard May 23 '15 at 14:42
  • 5
    It may be worth mentioning, that using the default manifest which is created by this method and which contains the node " as above makes at least not much sense and is confusing at least. I am not sure, if this could be even the source of further problems as the assemblyname and version in the manifest could be false and not taken from 'AssemblyInfo.cs' ? I use only the parts which make sense of that "template". Especially I am adding the operating system keys, e.g. for Win 10 which even VS 2013 doesn't know yet. – Philm Nov 11 '15 at 00:16
  • I wonder where the `Application Manifest File` template comes from, because there is nothing with that name (or even with `manifest` in the name) when I followed those instructions and looked at _every_ branch of the new item type tree. I'm using VS2019 16.11.5 (and started with v16.0.0, followed by every update) but I only install what I need to develop native C/C++ projects for Windows. I must need to install something I don't need to get this thing that I kinda need... Sigh. – Steve Valliere Nov 01 '21 at 11:54
  • @SteveValliere The manifest file could only be used in the .NET framework. I think you can't use it in a native C/C++ project. – ibram Nov 01 '21 at 15:17
39

As ibram stated, add the manifest thru solution explorer:

enter image description here

This creates a default manifest. Now, edit the manifest.

  • Update the assemblyIdentity name as your application.
  • Ask users to trust your application

enter image description here

  • Add supported OS

enter image description here

Jim Lahman
  • 2,691
  • 2
  • 25
  • 21
  • 7
    The `` node does not come up be default? Is it something you have added for a reason? I am using VS2015 – Horizon Aug 11 '16 at 08:52
13

The simplest way to create a manifest is:

  1. Project Properties -> Security -> Click "enable ClickOnce security settings"
    (it will generate default manifest in your project Properties)
  2. then Click it again in order to uncheck that Checkbox
  3. open your app.maifest and edit it as you wish.

Manifest location preview

shA.t
  • 16,580
  • 5
  • 54
  • 111
Kebechet
  • 1,461
  • 15
  • 31
4

In Visual Studio 2019 WinForm Projects, it is available under

Project Properties -> Application -> View Windows Settings (button)

enter image description here

Tejasvi Hegde
  • 2,694
  • 28
  • 20
3

In Visual Studio 2022 WinForm Project, it is also available under

Project Properties -> Application:

enter image description here

1

Go to obj folder in you app folder, then Debug. In there delete the manifest file and build again. It worked for me.

Isaac
  • 11
  • 1