アプリケーションとして実行Shell()を使用している管理者は(ターゲットファイルが常に管理者アクセスで実行されるように設定されていない限り)できません。
ProcessStartInfo
とProcess.Start()
を使用すると、管理者権限でアプリケーションを実行できます。しかし、Process.Start()は、ユーザーがNoを押した場合に例外を発生させます。
Dim psi As New ProcessStartInfo() ' Initialize ProcessStartInfo (psi)
psi.Verb = "runas" ' runas = Run As Administrator
psi.FileName = "cmd.exe" ' File or exe to run (this cannot take arguments, use ProcessStartInfo.Arguments instead
psi.Arguments = "/c " + TextBox1.Text + TextBox2.Text ' Arguments for the process that you're going to run
Try
Process.Start(psi) ' Run the process (User is required to press Yes to run the program with Administrator access)
Catch
MsgBox("User cancelled the operation", 16, "") ' User pressed No
End Try
「.NETアプリケーションを強制的に管理者として実行するにはどうすればよいですか? https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator – Werdna