作者:酸奶82 | 来源:互联网 | 2023-01-30 16:32
已成功使用2个文本框的内容运行DOS命令。我正在尝试解决的问题是…………。
如何以提升的权限运行(以管理员身份)
谁能帮我?
私有子Button1_Click(作为对象发送,作为EventArgs发送)处理Button1.Click Shell(“ cmd.exe / c” + TextBox1.Text + TextBox2.Text)结束子
1> 小智..:
不能使用Shell()以管理员身份运行应用程序(除非将目标文件设置为始终以管理员权限运行)。
而是使用ProcessStartInfo
and Process.Start()
:
Dim psi As New ProcessStartInfo()
psi.Verb = "runas" ' aka run as administrator
psi.FileName = "cmd.exe"
psi.Arguments = "/c " & TextBox1.Text & TextBox2.Text ' <- pass arguments for the command you want to run
Try
Process.Start(psi) ' <- run the process (user will be prompted to run with administrator access)
Catch
' exception raised if user declines the admin prompt
End Try