本文介绍了如何以管理员身份运行流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个运行批处理文件的进程.
但是此批处理文件需要管理员权限才能执行其任务.
我有以下代码:
I have a process which runs a batch file.
But this batch file need admin rights for doing its tasks.
I have the following code for it:
strtProcess = New Process
strtProcess.StartInfo.FileName = Application.StartupPath + "\extractor.bat"
strtProcess.StartInfo.Verb = "runas"
strtProcess.StartInfo.Arguments = ""
strtProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
strtProcess.StartInfo.UseShellExecute = True
但是我想在一个富文本框中显示该过程的输出.
有什么方法可以同时执行这两项任务,即以ADMIN身份运行文件?在RichTextBox中显示输出?
感谢ADVANCE
But I want to show the output of the process in a richtextbox.
Is there any method by which I can do both tasks i.e Run the File as ADMIN & show the output in RichTextBox?
THANKS IN ADVANCE
推荐答案
Process process = new Process();
ProcessStartInfo info = new ProcessStartInfo{FileName = "notepad",
UserName = "admin",
Domain = "",
Password = "myAdminPassword",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
process.Start(info);
您还可以将Process.Verb
属性设置为"runas",然后从那里开始.
You can also set the Process.Verb
property to "runas", and go from there.
这篇关于如何以管理员身份运行流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!