PyInstaller and Windows Vista/Server 2008

410 views
Skip to first unread message

Ant

unread,
Aug 1, 2008, 9:47:54 PM8/1/08
to PyInstaller
Hi,

Your help is needed:

I use pyinstaller 1.3 to create my python application that runs on
different Windows OS (W2K, W2K3, XP, and now Vista and Windows server
2008).
With Vista the User Access Control (UAC) is introduced. This requires
changes in the application manifest, where the application could
mention whether it is a standard user application, administrative
application, or mixed.

Example:
<?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.0"
processorArchitecture="X86"
name="myapp"
type="win32"/>

<description>My cool app</description>

<!-- Identify the application security requirements. -->

<ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-
com:asm.v2">
<ms_asmv2:security>
<ms_asmv2:requestedPrivileges>
<ms_asmv2:requestedExecutionLevel
level="requireAdministrator" uiAccess="false">
</ms_asmv2:requestedExecutionLevel>
</ms_asmv2:requestedPrivileges>
</ms_asmv2:security>
</ms_asmv2:trustInfo>

</assembly>


I need to change the application manifest and add these additional
attributes.

PyInstaller embeds a default application manifest file manifest.xml as
resource in to the binary. How do I change the manifest file according
to my needs before embedding it into the frozen exe?

Many thanks in advance for your help!
Antony

Giovanni Bajo

unread,
Aug 2, 2008, 7:52:52 AM8/2/08
to PyIns...@googlegroups.com

Antony,

if there's an official Microsoft tool to embed a manifest within an
executable, you should be able to run it onto the frozen executable
without problems. If you want to modify PyInstaller once for all for
this, you can run the same tool onto the bootloader executables (within
the support/loader directory). Of course, you will need to do the same
anytime you upgrade PyInstaller.

Otherwise, if you feel like contributing, you could leverage the
existing PyInstaller code that modifies an executable resource to add a
custom icon, so that it is able to also change the manifest, and
integrate this within the standard build flow. Let me know if you need
some guidance with this.
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


Ant

unread,
Aug 4, 2008, 1:56:59 AM8/4/08
to PyInstaller
Hi Giovanni,

Thank you for the quick response.
Microsoft recommends using mt.exe to embed the manifest file into the
binary.
I tried it, and found that it renders the python binary unusable! In
other words, the frozen python exe does not execute.
I tried it with Visual Studio 2005 as well, and with the same results.

This was why I thought of leveraging pyinstaller's own manifest file.

1) You have suggested updating the bootloader exes in support/loader
directory. I see many exes there, and presume them tobe debug console,
and windows and release console and windows. Apart from this, the exes
are named run_6*.exe and run_7*.exe.
Could you please let me know which are the ones used by pyinstaller?
And why exes with 6 and 7 numbers in their names?

2) I'll explore the possibility of leveraging the existing icon change
code, so that one could change the manifest as well.

Thanks,
Antony

Giovanni Bajo

unread,
Aug 4, 2008, 1:52:41 PM8/4/08
to PyIns...@googlegroups.com
On 8/4/2008 7:56 AM, Ant wrote:

> Thank you for the quick response.
> Microsoft recommends using mt.exe to embed the manifest file into the
> binary.
> I tried it, and found that it renders the python binary unusable! In
> other words, the frozen python exe does not execute.

I see. Probably, mt.exe strips data attacched to the executable.

> 1) You have suggested updating the bootloader exes in support/loader
> directory. I see many exes there, and presume them tobe debug console,
> and windows and release console and windows. Apart from this, the exes
> are named run_6*.exe and run_7*.exe.
> Could you please let me know which are the ones used by pyinstaller?
> And why exes with 6 and 7 numbers in their names?

They're for different Python versions. "6" means "Visual C++ 6", which
means Python 2.3 and below. "7" means "Visual C++ 7" which means Python
2.4 and above.

> 2) I'll explore the possibility of leveraging the existing icon change
> code, so that one could change the manifest as well.

OK let me know if you need any help with this.

Ant

unread,
Aug 5, 2008, 2:11:39 AM8/5/08
to PyInstaller
My frozen exe, which is 991KB in size, becomes 48KB after I run it
through mt.exe!

I thought that leveraging the icon code is a better solution, and made
changes accordingly:

1) I added appmanifest.py that contains this code:

RT_MANIFEST = 24


def EmbedManifest(dstpath, srcpath):
import os.path, string
if os.path.isfile(srcpath) is False:
return
# Read the manifest file contents into a buffer
data = open(srcpath, 'rb').read()
import win32api
print "Embedding application manifest to ", dstpath
hdst = win32api.BeginUpdateResource (dstpath, 0)
win32api.UpdateResource (hdst, RT_MANIFEST, 1, data)
win32api.EndUpdateResource (hdst, 0)

2) Then I modified assemble() method of ELFEXE class in Build.py, and
added code under if config['hasRsrcUpdate'] check (where icon and
version info are added to the exe):
# If manifest file exists in the same directory as the
spec file, insert it into the elfexe
manifest = os.path.join(SPECPATH, "manifest.xml")
if os.path.isfile(manifest):
print "Application manifest file found"
tmpnm = tempfile.mktemp()
shutil.copy2(exe, tmpnm)
os.chmod(tmpnm, 0755)
appmanifest.EmbedManifest(tmpnm, manifest)
trash.append(tmpnm)
exe = tmpnm
else:
print "No application manifest file found"

If the user creates manifest.xml and places it in the same directory
as his specfile, these code changes would insert the manifest into the
exe.

Please let me know whether these changes are ok.

Thanks,
Antony

Ant

unread,
Aug 5, 2008, 2:52:10 AM8/5/08
to PyInstaller
One more point with respect to command line executables:
With Windows Vista UAC, even command line applications could have
manifest embedded in them, to denote that they require admin
privileges when run.
So the application manifest is no longer only for GUI applications.

Hartmut Goebel

unread,
Aug 5, 2008, 3:33:59 AM8/5/08
to PyIns...@googlegroups.com
Ant schrieb:

> I thought that leveraging the icon code is a better solution, and made
> changes accordingly:

Can you please put this into the issue tracker, so it will not get lost.
Mind leaving your name, so we can credit this to you. Thanks.

> Please let me know whether these changes are ok.

If they work, it's fine :-)

--
Schönen Gruß - Regards
Hartmut Goebel

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de

Giovanni Bajo

unread,
Aug 5, 2008, 6:14:35 AM8/5/08
to PyIns...@googlegroups.com
On 8/5/2008 8:11 AM, Ant wrote:

> My frozen exe, which is 991KB in size, becomes 48KB after I run it
> through mt.exe!

Yes: probably mt.exe strips data attached to the executable.

I don't like the magic of checking for a specific file in the current
directory. A better approach is to add a new argument to ELFEXE, which
is the filename of the manifest to be added (or None - default - if
none); then, at the correct point, just embed the manifest if asked to do.

After this, you need a simple modification to Makespec.py to add a new
command line argument, and generate a .spec file with the specified
manifest. This makes it easier for people to embed manifests into the
executable.

To do these modifications, you can just look at the way icons are
handled and do the same for the manifest.

I would also appreciate a patch to the manual (doc/manual.txt) that
specifies the new option and how to use it.

Giovanni Bajo

unread,
Aug 5, 2008, 6:16:22 AM8/5/08
to PyIns...@googlegroups.com

Sure, that's fine.

One thing: how do people usually write manifests? Are they generated by
Visual Studio? Do they hand-code them? Do they use wizards?

Ant

unread,
Aug 5, 2008, 11:28:12 AM8/5/08
to PyInstaller
I believe for C++, C#, and .Net applications that are developed using
Visual Studio 2005, Visual Studio generates the template manifest
file.

In other cases, for example one is having a C++ exe but not the source
code, then s/he has to hand-code and embed it into the executable.

There is an application called Resource Tuner (http://
www.heaventools.com/resource-tuner.htm) that provides a wizard, which
generates the manifest file according to user inputs, and embeds them
into the executable. And guess what? This resource tuner tool was able
to embed my hand-coded manifest file into the python executable just
right!! This is something which both mt.exe and Visual Studio 2005
could not do!!
But this tool costs $199, which I did not want to buy, and ended up
making changes in pyinstaller! Thus saved $199! :-)

Thanks a lot for your help.
Antony

Noob

unread,
Aug 23, 2008, 4:43:35 PM8/23/08
to PyInstaller

> There is an application called Resource Tuner (http://www.heaventools.com/resource-tuner.htm)
> But this tool costs $199, which I did not want to buy, and ended up
> making changes in pyinstaller! Thus saved $199! :-)

Nope. For the record, Resource Tuner is just $39.95


Wbr,
Maxi
Reply all
Reply to author
Forward
0 new messages