Visual Studio 2010: How embed manifest with default settings - visual-studio

In Visual Studio 2010, i want it to embed a manifest with default settings:
Unfortunately the embedded manifest does not include a dependency on version 6 of the common controls library:
<?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="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>
</assembly>
This means that my WinForms application "doesn't use XP themes":
How to a convince Visual Studio 2010 to include a manifest that includes a dependancy on version 6 of the common controls library?

Cody had the answer to a question that has gone unresolved in Visual Studio for years, which helped me solve my problem.
Hans noted that you're not required to declare a dependancy on Common Controls Version 6 in order to get the version 6 library, which also helped me solve my problem.
So they should both get credit.

create your own manifest file. in notepad and save as app.manifest same code mentioned above with with level as administrator if you want code to run as admin level="requireAdministrator".
then import it to your project , add new item -> select the file.
later go to application properties and change the default manifest to the manifest file you created

Related

Service install on Windows 8,10 etc

I have a problem with the installation of the service.
I do it by default shortcut and a postscript or /install /uninstall depending on the need . Unfortunately, the program generates an error to stop the action .
Amazingly installation work properly on older environments.
Is there any other way to install the service?
The installation worked on older environments when UAC is turned off (which is a bad thing to do), you always need to run your installation program/script with elevated privileges (it has been like this since Windows Vista).
You can include a manifest so that your application/service requires elevation when executing with /install parameter.
To include a manifest, you need to create an xml file called manifest.xml with following contents:
<?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="YourApplication.exe" type="*" />
<description>elevate execution level</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*" />
</dependentAssembly>
</dependency>
</assembly>
Then create a file called manifest.rc with following content:
1 24 "Manifest.xml"
In modern Delphi versions, you can just include the rc file in the project via the project manager and Delphi will automatically include it as a resource. In older Delphi versions you need to manually compile the .rc file with brcc compiler to produce the .res file.
Have you try to run as administrator? Maybe it is a permission problem.
In modern Delphi versions : no need .rc
Go to Menu :
Project > Options > Application > Manifest File :
- AutoGenerate
- RequireAdminstrator
Best regards.

How to add an assembly manifest to a .NET executable?

How can i add an assembly manifest to my .NET executable?
An assembly manifest is is an XML file that is added to a .NET portable executable (PE) with resource type RT_MANIFEST (24).
Assembly manifests are used to declare a number of things about the executable, e.g.:
If i want to disable DPI-scaling because i am a good developer:
<!-- We are high-dpi aware on Windows Vista -->
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
i can declare that i was designed and tested on Windows 7, and i should continue to depend on any bugs in Windows 7
<!-- We were designed and tested on Windows 7 -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application>
</compatibility>
i can declare that i am a good developer, and don't need file and registry virtualization
<!-- Disable file and registry virtualization -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
i can declare that i depend on a particular version 6 of the Microsoft Common Controls library:
<!-- Dependency on Common Controls version 6 -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
i can declare that i depend on a particular version of GDI+:
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.GdiPlus" version="1.0.0.0" processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df" language="*" />
</dependentAssembly>
</dependency>
In the olden days, we would create a resource script file (*.rc), e.g.:
wumpa.rc
1 24 AssemblyManifest.xml
add that file to the project, and the compiler would compile the .rc file; including resources in the final executable image.
Except Visual Studio 2010 doesn't seem to have a way to add a resource script file to a project.
How do i add a resource script to a project in Visual Studio 2010?
How do i add an assembly manifest to a project in Visual Studio 2010?
Note: Any solution must work in an environment with source control and multiple developers (e.g. hard-coded paths to probably not installed binaries will break the build and not work).
Bonus Chatter
VS2010/.NET: How to embed a resource in a .NET PE executable?
VS2005: How to embed a manifest in an assembly: let me count the ways... (can't be done)
Update: Michael Fox suggests that the project properties dialog can be used to include an assembly manifest, but he doesn't indicate where:
Update: Things I've tried:
From the project properties screen, select Application. Select radio option Icon and Manifest. Under Manifest leave the default option of Embed manifest with default settings:
Doesn't work because it embeds a manifest with default settings, rather than my settings.
Under Manifest, change the combo option to Create application without a manifest:
Doesn't work because it embeds no manifest
Under Resources select the Resource File radio option:
Doesn't work because you cannot select an assembly manifest (or a resource script that includes an assembly manifest)
Under Resources, select the Resource File radio option, then enter the path to an assembly manifest XML file:
Doesn't work because Visual Studio chokes when presented with an assembly manifest:
Under Resources, select the Resource File radio option, then enter the path to a resource script file:
Doesn't work because Visual Studio chokes when presented with a resource script:
Add the AssemblyManifest.xml to my project, then look for it in the Manifest combo box:
Doesn't work because the Assembly Manifest file isn't listed as an option
i have a dozen other things i can keep screenshotting (add a .rc file to the solution, look for it in the dropdown, select "no manifest" and change the wumpa.rc build action to various things, build the .rc file using a separate resource compiler, either manually, or a pre-build/msbuild step, and select that .res file as my resource). i'll stop adding extra bulk to my question and hope for an answer.
If you want to add custom information to your application's manifest, you can follow these steps:
Right-click on the project in the Solution Explorer.
Click "Add New Item".
Select "Application Manifest File".
This adds a file named app.manifest to your project, which you can open and modify as desired.
Similar steps, with screenshots, lifted from Declaring Managed Applications As DPI-Aware on MSDN:
In the Solution Explorer, right-click on your project, point to Add, and then click New Item.
In the Add New Item dialog box, select Application Manifest File, and then click Add. The app.manifest file appears.
Copy and paste the following text into the app.manifest file and then save.
<?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"/>
<!-- Disable file and registry virtualization. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<!-- <requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
-->
</requestedPrivileges>
</security>
</trustInfo>
<!-- We are high-dpi aware on Windows Vista -->
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<!-- Declare that we were designed to work with Windows Vista and Windows 7-->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</asmv1:assembly>
In the Solution Explorer, right-click on the project, and then click Properties to verify that the app.manifest is used.
Your application is now manifested as required to be "designed for Windows", and is
disables file and registry virtualization
disables DWM scaling of applications
announces that you were designed and tested on Windows 7 and Windows Vista
takes a dependency on Common Controls library version 6 (enabling the use of visual styles by the common controls)
I have Visual Studio 2010 Professional with Service Pack 1 installed. I am running on Windows 7 Ultimate 64-bit. If I follow these instructions, the project properties shows "Embed manifest with default settings" in the resources block, and also the option is disabled! When I build, the manifest does not get embedded into the DLL as I verified by opening the DLL in resource view.
However, if I :
Locate the added app.manifest file in the Solution Explorer
Right-click and choose Properties
Change the Build Action property from "None" to "Embedded Resource"
Rebuild
The manifest file is embedded properly, which I can verify by loading the DLL into the resource view. The Manifest setting in the Application properties still shows as "Embed manifest with default settings" and is still disabled.
In Visual Studio 2008, this can be done in the Project Properties window. I'm almost positive it is the same in 2010. Right click on your project, select properties, and in the application tab you can select a manifest. You have to add it to your project first, but you can do that easily by adding an existing file.

VB6 Manifest not working on Windows 7

I have created a manifest file for a VB6 application that is running on Windows 7 (not for any visual style changes, just to make sure it accesses the common registry and not a virtualised one)
The exe name is Capadm40.exe, the manifest is named Capadm40.exe.manifest and contains the following:
<?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="CompanyName.Capadm40"
type="win32"/>
<description>Administers the System</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
However, this doesn't seem to make any difference. ie the application is still using the virtualised registry hive. What is also strange is the after I unticked the 'Run this program as an administrator' option in the properties of the application exe, windows still shows a shield on the application icon, leading my to think this is some issue with my windows installation rather than a fault with the manifest. Any ideas?
You're probably running afoul of the fusion cache (and the Explorer Shell's icon cache). External manifests are strongly discouraged anyway, but trying to add one after the program has previously been run often leads to such symptoms.
See Manifest and the fusion cache for a brief description.
You could also touch the EXE to reload the cache.
I would take advantage of LaVolpe's manifest creator, works great for XP, Vista and 7: http://www.vbforums.com/showthread.php?t=606736
I have only found one manifest that works across all platforms 9x+. or even works at all. I have tried all the examples, articles, etc.
the version number or anything else added to it will kill it. possible exception is the extra parameter on requestedExecutionLevel, that seems to be OK. you can change level, and you can add uiAccess. those are allowable. after a LOT of binary-count testing, I found out that those cute extra features of manifests that microsoft offers simply make windows give various errors.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
<ms_asmv2:security>
<ms_asmv2:requestedPrivileges>
<ms_asmv2:requestedExecutionLevel level="asInvoker">
</ms_asmv2:requestedExecutionLevel>
</ms_asmv2:requestedPrivileges>
</ms_asmv2:security>
</ms_asmv2:trustInfo>
</assembly>
Applying the styles in the VB6 IDE:
Save this text in a file named vb6.exe.manifest in the same folder as the vb6.exe:
<?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="Microsoft.VisualBasic.IDE"
type="win32"
/>
<description>Visual Basic 6 IDE</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
Add spaces in the file end until it reaches 672 bytes (multiple of 4).
Then:
download the Resource Hacker and open it as administrator
File > open the VB6.exe
File > New blank script
type:
1 24 "vb6.exe.manifest"
Compile script
Save

Delphi app manifest file problems under WinXP and Win7

My last question "List service and services status under Win-7" made me start working on a solution that gives my app the admin privileges under Windows Vista onward based on a .manifest file.
I was not sure about continue the previous question with this matter since they are not the same so here is another question:
My app now works fine under Win 7 whether or not I run it "as admin" because of the manifest file.
My manifest file is as follow:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.6.0.5" processorArchitecture="X86" name="ServiceMonitorPro" type="win32"/>
<description publisher="Powershield Ltd" product="Powershield Service Monitor">Powershield Service Monitor</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
When the application runs on windows 7 or Vista, the UAC comes with a dialog like this:
alt text http://www.freeimagehosting.net/uploads/39787fd3dd.jpg
How can I replace the "unknow" publisher?
The other and bigest problem is, even thou the app runs with no problem under Win7 or Vista, under WinXP it is now crashing with the message:
"This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."
Another thing I would like to add: If
I add reference (uses clause) to XPMan
the app works fine on WinXP but then
it my .manifest file makes no
diference under Vista or Win7.
I have to thank everyone that, with comments or answers point me to keep digging... :)
I went to search for the file WindowsXP.res.
The content of that file is:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="DelphiApplication"
version="1.0.0.0"
processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
</assembly>
The solution: I have mixed my .manifest file with the WindowsXP.Res xml one adding the dependency section.
If anyone know why its now working, I would be glad to hear about - but this was the solution here - tested so far in a couple of virtual machines, on my computer and a couple of others... working :)
You need to sign your code with a code signing certificate. There should be lots of examples here. I have re-tagged your question with "code-signing", and you can also look for "certificate".
I use Comodo certs myself, and sign them with the awesome, wonderful, Visual Build Pro v6, which is an advertiser here on SO.
You can indicate compatibility with various versions of Windows in your manifest as well. I know that there are entries for compatibility with Vista and Win7; not sure about XP.
Info about the manifest compatibility section is available at MSDN. This may help, also - from the linked page:
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application>
</compatibility>
On newer versions of Delphi (7 and above I think) you also need to also be sure to uncheck the "Use Runtime Themes" option in your project options dialog, otherwise Delphi will automatically link in its own default manifest file (that's how it enables the "theme support") and you will get a runtime error about the application's configuration being incorrect, because there will be conflicting entries.
Here's a complete manifest file for a Delphi2007 app which needs to run in adminstrator mode in Windows 7, and also includes the "dependency" section to enable runtime theme support:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="CodeGear RAD Studio"
version="11.0.2902.10471"
processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

Why is my VB6 application manifest ignored on 64bit machines?

I have the following manifest embedded in a VB6 application.
<?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="ExeName"
type="win32"/>
<description>elevate execution level</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
On 32bit Server 2008 machines the file correctly appears with a "Admin Shield" icon overlay and can only be run as administrator. On 64bit Server 2008 the same file does not have the icon overlay and can be run normally.
I have tried changing the processorArchitecture="X86" to both "*" and "ia64" and also removing the manifest from the compiled application and having it as a external manifest, all to no avail.
Any thoughts gratefully recieved.
Have you tried embedding your manifest as this post suggest?
http://www.xtremevbtalk.com/showthread.php?t=308937
Answer is near the bottom of the post with a link to:
http://blogs.msdn.com/vistacompatteam/archive/2006/11/13/manifest-and-the-fusion-cache.aspx
Because your processorArchitecture attribute indicates that it is a 32bit machine.

Resources