Click here to Skip to main content
15,885,216 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:
VB
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?

THANKS IN ADVANCE
Posted
Updated 28-Mar-20 3:41am
v2
Comments
Dalek Dave 16-Apr-11 9:37am    
Edited for Readability.
kiquenet.com 15-Oct-14 13:31pm    
Not work for Redirect IO http://kiquenet.wordpress.com/2014/08/22/uac-run-as-administrator-elevated-process/

Here's one way:

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


You can also set the Process.Verb property to "runas", and go from there.
 
Share this answer
 
Comments
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 vb.net??
#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.
kiquenet.com 15-Oct-14 13:32pm    
Not works for RedirectIO and runas: http://kiquenet.wordpress.com/2014/08/22/uac-run-as-administrator-elevated-process/
I hope This[^] might be Helpful.

Have a look on Link 1[^], Link 2[^], Link 3[^] also.
 
Share this answer
 
Comments
kiquenet.com 15-Oct-14 13:32pm    
Not works for RedirectIO and runas: http://kiquenet.wordpress.com/2014/08/22/uac-run-as-administrator-elevated-process/

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