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”
- Go to project and select “(Project Name) properties…”
- Click on “View UAC Settings”
- Find the code “<requestedExecutionLevel level=”asInvoker” uiAccess=”false” />”
- Replace the code with “<requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” />”
- You will be able to run your sample code now.
- Later, when the code is compiled to executable (exe), this VB.Net application will also run as “Administrator”.
Source:
- http://www.downloadinformer.com/how-to-make-a-vb-net-application-always-run-in-administrator-mode/
- https://www.codeguru.com/vb/gen/vb_system/accessing-administrative-privileges-from-your-visual-basic-programs.html
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”
Step 2: Right click on “vbexpress.exe” and select “Properties”
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.