Freigeben über


Make your program run as admin on Vista

Whenever I look at sample code I always poke around to find interesting things.  I was looking over the new .NET Framework 3.5 Enhancements Training Kit and I found something interesting,

They have some tools in the labs setup that run as administrator.  This allows them to create things like database aliases.  I found this when I ran through the ADO.NET Data Services lab - which was very cool by the way.

It turns out that by including a manifest with your project you can specify that require admin privileges to run.

The manifest file looks like this

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
       processorArchitecture="X86"
       name="AliasDatabaseServer"
       type="win32" />
  <description>AlaiasDatabaseServer manifest</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

 

I noticed that they embedded the manifest as a resource with the project. I don't know why they did it this way (perhaps this was the way to do it in VS2005?).  In VS2008 all you have to do is to right click on your project and select Add New Item to add an app.manifest file.  Uncomment the selection you want and it will also alter the project properties for you to include the manifest.

I'm sure many of you are saying... duh! I can't believe Ron didn't know this.  Well - I didn't and now you do.

So check out the new training kit - you might learn something.

Framework and BizTalk Best Practices with an Eye towards Oslo

Speaking of learning something.  I just posted another endpoint.tv episode where I interviewed Jon Flanders about what you can do today to get ready for "Oslo".  Check it out here

Comments