Assembly manifest and Its Applications in Vista and win7

Source: Internet
Author: User

Each assembly, whether static or dynamic, contains a set of data that describes how each element in the Assembly is associated with each other. The Assembly list contains the Assembly metadata. Assembly List includes

Specify the version requirements and all metadata required for the assembly, and define the scope of the Assembly and all metadata required for parsing references to resources and classes. The Assembly List can be stored in

PE files (.exe or. dll) with Microsoft intermediate language (msil) code can also be stored in independent PE files that only contain assembly list information.

For an assembly with an associated file, this list will be merged into the PE file to form a single file assembly. You can create an independent configuration file or merge the configuration into the same multi-file assembly.

Multi-file assembly of a PE file.

The list of each Assembly performs the following functions:

1. enumerate the files that constitute the assembly.
2. control how to map the type and resource reference of the Assembly to the file containing its declaration and implementation.
3. enumerate other assemblies on which the Assembly depends.
4. provide a certain degree of indirect information between the user of the Assembly and the user of the Implementation Details of the Assembly.
5. Present the Assembly self-report.

The assembly manifest content is described in XML file format, and the extension is (. manifest), for an application, we can associate the Assembly List to control the permission level to be run, and the style used when the execution program needs to run.

The following assembly manifest example requires administrator permissions for your program in Vista and win7, that is, the UAC Privilege Escalation dialog box is displayed when the program is running.

View code copy code print code about
  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 = "test.exe. manifest"
  7. Type = "Win32"
  8. />
  9. <Trustinfo xmlns = "urn: Schemas-Microsoft-com: ASM. V3">
  10. <Security>
  11. <Requestedprivileges>
  12. <Requestedexecutionlevel level = "requireadministrator" UIAccess = "false"/>
  13. </Requestedprivileges>
  14. </Security>
  15. </Trustinfo>
  16. </Assembly>

If you want to change the Windows User Account Control level, replace the requestedexecutionlevel node with one of the following nodes.

View code copy code print code about
  1. <! -- General permission -->
  2. <Requestedexecutionlevel level = "asinvoker" UIAccess = "false"/>
  3. <! -- Administrator privilege -->
  4. <Requestedexecutionlevel level = "requireadministrator" UIAccess = "false"/>
  5. <! -- Maximum permission -->
  6. <Requestedexecutionlevel level = "highestavailable" UIAccess = "false"/>

Generally, there are two types of association: internal program embedding and external Association.

The procedure for embedding a program is as follows:
1. create an assembly manifest file named "your application name. manifest ". If your generated file is" test.exe ", the Assembly List (assembly manifest) is named" test.exe. manifest ".
2. select the newly created Assembly List (Assembly manifest.pdf file (test.exe. manifest), enter "rt_manifest" in the pop-up resource type dialog box, find the resource you just added, and change its ID attribute to 1. Of course, for internal embedding, the Assembly list file name, resource types and IDS can be customized.
3. recompile your program.

The external association method is as follows:
1. create an assembly manifest file named "your application name. manifest ". If your generated file is" test.exe ", the Assembly List (assembly manifest) is named" test.exe. manifest ".
2. Put "test.exe. manifest" in the same directory of your compiled "test.exe.

Note: If you use the internal program embedding method and the Assembly List defines that administrator permissions are required or the preceding permissions are required, the compiled program icons are marked with a small shield, and the external association does not display a small shield.

The following program configuration file allows your program to use WINXP controls:

View code copy code print code about
  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 = "test.exe. manifest"
  7. Type = "Win32"
  8. />
  9. <Description> test application for XP style. </description>
  10. <Dependency>
  11. <Dependentassembly>
  12. <Assemblyidentity
  13. Type = "Win32"
  14. Name = "Microsoft. Windows. Common-Controls"
  15. Version = "6.0.0.0"
  16. Processorarchitecture = "x86"
  17. Publickeytoken = "6595b64144ccf1df"
  18. Language = "*"
  19. />
  20. </Dependentassembly>
  21. </Dependency>
  22. </Assembly>

It should be noted that the program runs XP and later systems, and the vc6 compilation that I tested can only use the internal program embedding method. Follow the steps described above, enter "24" (number only) in the imported resource type, find the added resource, and modify its ID attribute "1" (number only ). For vc7 and later versions, you can use external Association.

All of the above have been tested successfully in vc6 + win7!

The following describes how to use a program compiled by VC. Net to run the program on a computer without the. NET Framework installed. For example, run the program in the newly installed XP system. "the application fails to be started due to incorrect application configuration. Re-installing the application may correct this problem. . Use vs2008sp1 as

For example, we use the Wizard to generate a Common Dialog Box program (MFC application ).

1. choose Project Properties> manifest tool> input and output> embed manifest and select "no". In this way, the program list file is not automatically embedded during compilation, we use the external program inventory file for modification. Of course, there is a way to modify the internal program embedding.
2. Open "Vc \ redist \ x86 \ microsoft. vc90.crt" in the vs2008 installation directory, which contains four files: Microsoft. vc90.crt. manifest, msvcm90.dll, msvcp90.dll, and msvcr90.dll.
3. open the path "Vc \ redist \ x86 \ Microsoft. vc90.mfc ", which contains Microsoft. vc90.mfc. manifest, mfc90.dll, mfc90u. DLL, mfcm90.dll, and mfcm90u. DLL files.
4. Use notepad to open the Microsoft. vc90.crt. manifest file. You can find the version number "version = 9.0.30729.1" and write down the version numbers for backup.
5. generate the release version of your application, and use dependency Walker to view the dependent libraries. Here we should be "mfc90.dll" and "msvcr90.dll", and copy these two files and "Microsoft. vc90.crt. manifest "and" Microsoft. vc90.mfc. copy manifest to the same directory as the generated exe.
6. create "your application name" in the same directory as the application you generated. manifest "file. If your program is" test.exe ", the created file name is" test.exe. manifest ". Enter the following code (note that the version in the following code must be consistent with the version you noted down above ):

View code copy code print code about
  1. <? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>
  2. <Assembly xmlns = "urn: Schemas-Microsoft-com: ASM. V1" manifestversion = "1.0">
  3. <Dependency>
  4. <Dependentassembly>
  5. <Assemblyidentity type = "Win32" name = "Microsoft. vc90.crt" version = "9.0.30729.1"
  6. Processorarchitecture = "x86" publickeytoken = "1fc8b3b9a1e18e3b"> </assemblyidentity>
  7. </Dependentassembly>
  8. </Dependency>
  9. <Dependency>
  10. <Dependentassembly>
  11. <Assemblyidentity type = "Win32" name = "Microsoft. vc90.mfc" version = "9.0.30729.1"
  12. Processorarchitecture = "x86" publickeytoken = "1fc8b3b9a1e18e3b"> </assemblyidentity>
  13. </Dependentassembly>
  14. </Dependency>
  15. <Trustinfo xmlns = "urn: Schemas-Microsoft-com: ASM. V3">
  16. <Security>
  17. <Requestedprivileges>
  18. <Requestedexecutionlevel level = "asinvoker" UIAccess = "false">
  19. </Requestedexecutionlevel>
  20. </Requestedprivileges>
  21. </Security>
  22. </Trustinfo>
  23. </Assembly>

The above Runtime Library has passed the test in vs2008 SP1 and the new WINXP SP3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.