[vb.net] uac自提升后运行代码 [英] [vb.net] run codes after uac self elevation

查看:149
本文介绍了[vb.net] uac自提升后运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在uac自提升之后运行代码.
基本上,当我单击按钮后,一旦它升高,它应该向注册表添加密钥.到目前为止,我设法获得了自我海拔部分,并增加了注册表部分.现在我似乎无法使其一次单击即可运行.

根据我的研究,自我标高代码正在运行另一个实例并关闭当前实例.但是当发生这种情况时,新实例不会继续执行代码.有没有解决的办法.

Hi, I am wondering how to run codes after uac self elevation.
basically when i click a button once it elevated it suppose to add a key to the registry. so far i manage to get the self elevation part and the adding the registry part. now i cannot seem to make it run in a single click.

from my research the self elevation code are running another instance and closing the the current one. but when that happen that new instance does not continue the code. is there a work around for it.

Dim proc As New ProcessStartInfo

        proc.UseShellExecute = True
        proc.WorkingDirectory = "c:\debug"
        proc.FileName = "test.exe"
        proc.Verb = "runas"

        If IsRunAsAdmin() = False Then

            Try

                Process.Start(proc)
                Application.Exit()

            Catch
                ' The user refused to allow privileges elevation. 
                MsgBox("Permission denied by user ! Can not proceed.", MsgBoxStyle.Critical)

                Return

            End Try
        Else

            MessageBox.Show("Already Running as Admin")

        End If


    End Sub





Friend Function IsRunAsAdmin() As Boolean

       Dim principal As New WindowsPrincipal(WindowsIdentity.GetCurrent)

       Return principal.IsInRole(WindowsBuiltInRole.Administrator)

   End Function

推荐答案

为什么不将所需的特权添加到应用程序清单中.您不必每次都执行上述指定的检查.

检查此(创建并嵌入应用程序清单(UAC)) [ ^ ].
Why don''t you add your required privilege to your application manifest. You need not to perform the above specified check every time.

Check this (Create and Embed an Application Manifest (UAC))[^].


这篇关于[vb.net] uac自提升后运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆