views:

142

answers:

1

Hi,

I am embedding a manifest in a .NET exe so that it can request elevated permissions in Vista and Windows 7. The manifest that I am using is as follows:

<?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="ElevationTest" type="win32"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

It works as expected in Vista and Windows 7 but crashes XP with the standard "... has encountered a problem and needs to close..." error. If I don't embed any manifest then it works as expected but will obviously not have the required permissions in Vista and Windows 7.

What is a standard way of producing an exe that will function with the correct permissions in XP and Vista / Windows 7?

Thanks, Alan

+1  A: 

I think the manifest may be a red herring. I've just created a console application with that manifest embedded, targetting .NET 2.0 and it runs happily on XP SP3.

Have you tried running the app on XP without the manifest embedded? Also, which version of .NET are you targetting, what type of .NET app is it (WPF, WinForms, service, etc) and finally (I have to ask), is the correct version of .NET installed on that XP machine?

John Conners
Thanks for your reply John.Yes, I have tried running the app without the manifest embedded and it works.I am targetting .NET 2.0 SP1 with a WinForms app.The correct version of .NET is installed on the XP machine. For information, I am running XP SP2 not SP3.Alan
Alan Spark
Hmmm. What happens if you create a new WinForms app, apply the manifest and attempt to run that on your XP machine? Just tested that on XP SP2 this time and still no crash for me. If it does crash then I'd recommend repairing .NET (I've seen .NET behaving very strangely like this before and a repair normally sorts it out). Failing that, have you tried running on a different XP box? Failing that, have you added a new handler to Application.ThreadException to catch unhandled exceptions and see if you can catch the crash and grab the call stack?
John Conners
Hi John.After much more experimeting I have found the cause of the crash. I was applying a strong name to my exe. The combination of the manifest and the strong name was causing the crash. For me, strong naming was not essential so I have turned it off.Thanks again for your help.Alan
Alan Spark
Very strange indeed! Cool, glad you've got it working!
John Conners