Click here to Skip to main content
14,734,606 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

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?

Updated 28-Mar-20 4:41am
Dalek Dave 16-Apr-11 9:37am
Edited for Readability. 15-Oct-14 13:31pm
Not work for Redirect IO

Here's one way:

Process process = new Process();
ProcessStartInfo info = new ProcessStartInfo{FileName = "notepad",
                                             UserName = "admin",
                                             Domain = "",
                                             Password = "myAdminPassword",
                                             UseShellExecute = false,
                                             RedirectStandardOutput = true,
                                             RedirectStandardError = true

You can also set the Process.Verb property to "runas", and go from there.
Albin Abel 16-Apr-11 8:20am
Good solution.
rahuliyer95 16-Apr-11 9:54am
But how do I get to know the admin user name and password from
#realJSOP 16-Apr-11 10:04am
You can't. I assumed you had an admin password. Looks like you're going to have to use the Process.Verb approach. 15-Oct-14 13:32pm
Not works for RedirectIO and runas:
I hope This[^] might be Helpful.

Have a look on Link 1[^], Link 2[^], Link 3[^] also.
Comments 15-Oct-14 13:32pm
Not works for RedirectIO and runas:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900