Run another program as administrator

半腔热情 提交于 2019-11-28 11:24:50

You can run another application from your application by using:

Process.Start("Notepad.exe")

If your original program is running Elevated (As Admin), then Notepad will run As Admin (there will be no UAC prompt)

If your original program is not running Elevated and you want to start an application elevated (As Admin) you will have to do something like this (this will prompt for elevation):

    Dim procStartInfo As New ProcessStartInfo
    Dim procExecuting As New Process

    With procStartInfo
        .UseShellExecute = True
        .FileName = "Notepad.exe"
        .WindowStyle = ProcessWindowStyle.Normal
        .Verb = "runas" 'add this to prompt for elevation
    End With

    procExecuting = Process.Start(procStartInfo)

Note that there is no way to circumvent the UAC prompt. If UAC is enabled then the user will have to agree to the elevation at some point.

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