How does a program ask for administrator privileges?

Deadly 提交于 2019-11-28 12:48:17

There are a number of methods depending on your needs. Some details are given in the application developer requirements for UAC.

  1. Include a UAC manifest that causes your program to require administrator privileges at startup.
  2. Use one of the suggested methods for invoking an elevation to run out of process. One of the nicest is to use the COM elevation moniker and CoCreateInstanceAsAdmin to call methods on a COM object running as an administrator. This is possibly tricky to get working in VB.Net. I got it working ok in C++ though
  3. Another ok method is to isolate the parts of your code that need admin privileges into an application that uses a UAC manifest to require admin privileges. Your main app does not need to run as an admin in that case. When you require admin privilegese, you would invoke the external application.

You can specify this in your application's manifest file.

Check out this link and this link and this link too.

AnOnYmOuS
 Try
                    Dim procInfo As New ProcessStartInfo()
                    procInfo.UseShellExecute = True
                    procInfo.FileName = 'Filename here
                    procInfo.WorkingDirectory = ""
                    procInfo.Verb = "runas"
                    Process.Start(procInfo)
                Catch ex As Exception
                    MsgBox(ex.Message.ToString(), vbCritical)
                End Try
            End If

The most easy way to do this is to click on the Project tab -> Add Windows Form -> .XML file -> name it (program name).manifest -> paste this code in this link into it ( thanks JDOConal ) -> then right click on your project name in the solution explorer box off to the right and hit properties -> on the first tab select manifest and then the .manifest file you created -> build = done!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!