How to Run Code as an Administrator

Whenever you see this error message

“Cannot open [Windows service name] on computer “


you need to run the VB.Net code as an “Administrator”. There are 2 solutions available.

Solution 1: Modifying “app.manifest”

  1. Go to project and select “(Project Name) properties…”
  2. Click on “View UAC Settings”
  3. Find the code “<requestedExecutionLevel level=”asInvoker” uiAccess=”false” />”
  4. Replace the code with “<requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” />”
  5. You will be able to run your sample code now.
  6. Later, when the code is compiled to executable (exe), this VB.Net application will also run as “Administrator”.




Solution 2: Running Visual Studio as an “Administrator”

Step 1: Find Visual Studio IDE in program files, for my machine it is located at “C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE”a

Step 2: Right click on “vbexpress.exe” and select “Properties”b

Step 3: Click on “Compatibility”, then check on “Run this program as an administrator” , then click “OK”

Step 4: Run the program and it will run as administrator.