user1544479
user1544479

Reputation: 1007

How can I make that when I run my application thorugh the VS it will prompt for admin rights?

I can do it in the application Debug/Bin directory to change the exe file of my application property to Run As Admin.

But I want it to run as admin also when I'm running it through Visual Studio.

So I created a manifest file which I put it in the debug/bin directory of my application and I also have there mt.exe

My manifest file content:

Executable: hardwareMonitoring.exe 
Manifest:Hardwaremonitoring.exe.manifest
Sample application manifest file:
<?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="IsUserAdmin"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

Now I think I need to use the mt.exe somehow or need to add/embed the manifest into my project? The idea is that not it will create automatic on my hard disk in Debug/Bin a exe file which is already in Admin Rights (Run As Admin) but I want it to prompt for admin right confirmation when I'm running the application in Visual Studio 2010.

Upvotes: 0

Views: 796

Answers (2)

user1544479
user1544479

Reputation: 1007

I had it somewhere i kept it on a text file:

First you create a text file with notepad and add to it:

Executable: hardwareMonitoring.exe 
Manifest:Hardwaremonitoring.exe.manifest
Sample application manifest file:
<?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="IsUserAdmin"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

Then you save the file name as: appName.exe.manifest Then you click on the windows Start>Cmd type in the dos window:

mt -manifest appName.exe.manife
st.txt -outputresource:appName.exe;#1

If mt.exe is not the application: Debug/Bin directory just give the directory/ies before the mt.

Thats it.

Upvotes: 0

caoquendo
caoquendo

Reputation: 496

When you debug an application (say hello.exe) it is usually run through a proxy application called vshost.exe. That application has the same privileges as the instance of VS you are using.

You can try launching Visual Studio with administrative privileges so vshost.exe and your application is launched with that privileges too.

Upvotes: 2

Related Questions