Some Time Ago...
I wrote a blog entry, PE Files, UAC, Reg-Free COM, and Other Crazy Stuff - Part 2
, that detailed how to view and edit the application manifest that is inserted into VFP compiled modules. I also took some time to explain why someone would want to do such a thing. The top two reasons most VFP developers want to do this is to elevate permissions under Window's User Account Control
(UAC) and to provide for Registration-Free COM
. I guess you may also find the need to edit or add strings to the PE file's String Table resource (minority of VFP developers) which is provided for as well.
While the code and concepts detailed in that previous blog entry were advanced and pretty decent (if i do say so myself), it suffered from a couple of bugs and most VFP developers probably found it more than a little difficult to implement "out-of-the-box" for their projects that needed elevated UAC permissions or Reg-Free COM. I attempt to make things slightly more straight-forward and bug-free in this blog entry.Enter the ProjectHook Class
There's plenty of good information on the ProjectHook class online
and in the VFP 9.0 SP2 help file (get the latest and greatest help file out on VFPX
), so I won't go into a great amount of detail here. I simply wanted an easy way to apply a new manifest to a VFP executable after I had built a project. The ProjectHook class provides a BeforeBuild
event where I can get the fullpath of the EXE being built and an AfterBuild
event which allows me to perform operations immediately after the EXE is built. So, this class provided exactly what i needed and made applying a modified manifest a breeze.How to Use ProjectHookEx.vcx
In order to use the projecthookex.vcx (download provided at the bottom of this blog entry), you simply need to unzip and copy it somewhere and then open up one of your projects and go into the Project Information dialog (accessible either by right-clicking the project or under the Project system menu... look for Project Info) and set the Project Class property as shown in the following screen shot...
...then simply click OK, exit your project and reopen your project. The projecthook isn't instantiated until you reopen the project for the first time after setting the Project Class property.
The default settings for the hookex class are set so that the default VFP 9.0 SP2 manifest, which has its trustinfo
set to asInvoker, is changed to requireAdministrator. Take a look inside hookex's AfterBuild event for the code that accomplishes this (short and sweet). You'll see a couple commented out lines of code in the AfterBuild event that show how to accomplish Reg-Free COM and String Table resource edits as well. In any event, once the Project Class is set for your project hookex will be instantiated and ready to go any time you open and build your project. When the manifest is applied it will be echoed to the screen so you can see it and ensure that it has been applied (you can turn this off by changing the moduleresourceeditor class's showmanifestafterapplying
property if you so desire).External Manifests Anyone?
For those of you that prefer to use an external manifest for your executables, you can do so by setting the moduleresourceeditor class's externalmanifest property. The cool thing about this is that the myproj.exe.manifest file is created in the same directory as your executable and the executable's internal manifest is removed to prevent it from interfering with your external manifest. Then you can edit the external manifest using favorite XML editor or even notepad. This was one of the enhancements I added to this that is not in the code that I posted in the original blog entry regarding PE Assembly/Application Manifests.What's Next
There are plenty of improvements and enhancements (automatically searching project for all COM components and automatically adding them to the manifest for instance) that could be made to this class and I hope that my readers will make suggestions and even try their hand at coding a few. There are lots of good uses for VFP's ProjectHook
class. I'd love to hear from you and what you feel needs to be done to improve this ProjectHook class. But, I'm cool if you just want to read this, download the class library and use it. Until next time... VFP Rocks!Download the Latest Version of the ProjectHookEx Class Library
(12 KB approx.)