B
Broggy69
Guest
I am trying to run a powershell command with admin rights and display the results in a text box.
They only thing not working is the running as admin. I have my startinforverb = "runas"
Below is my code:
Dim objProcess As New Process()
objProcess.StartInfo.Verb = "runas"
objProcess.StartInfo.FileName = "powershell.exe"
objProcess.StartInfo.Arguments = "E:\Install\3rdParty\Additional_Support_files\Windows_Firewall.ps1"
objProcess.StartInfo.RedirectStandardOutput = True
objProcess.StartInfo.RedirectStandardError = True
objProcess.StartInfo.UseShellExecute = False
objProcess.StartInfo.CreateNoWindow = True
objProcess.Start()
Dim output As String = objProcess.StandardOutput.ReadToEnd()
Dim errors As String = objProcess.StandardError.ReadToEnd()
txt_log.Text += "Output:" + Environment.NewLine
txt_log.Text += "-------" + Environment.NewLine
txt_log.Text += output + Environment.NewLine
txt_log.Text += Environment.NewLine
txt_log.Text += "Errors:" + Environment.NewLine
txt_log.Text += "-------" + Environment.NewLine
txt_log.Text += errors + Environment.NewLine
Here is the result I get:
Output:
-------
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
Errors:
-------
Any help would be appreciated
Continue reading...
They only thing not working is the running as admin. I have my startinforverb = "runas"
Below is my code:
Dim objProcess As New Process()
objProcess.StartInfo.Verb = "runas"
objProcess.StartInfo.FileName = "powershell.exe"
objProcess.StartInfo.Arguments = "E:\Install\3rdParty\Additional_Support_files\Windows_Firewall.ps1"
objProcess.StartInfo.RedirectStandardOutput = True
objProcess.StartInfo.RedirectStandardError = True
objProcess.StartInfo.UseShellExecute = False
objProcess.StartInfo.CreateNoWindow = True
objProcess.Start()
Dim output As String = objProcess.StandardOutput.ReadToEnd()
Dim errors As String = objProcess.StandardError.ReadToEnd()
txt_log.Text += "Output:" + Environment.NewLine
txt_log.Text += "-------" + Environment.NewLine
txt_log.Text += output + Environment.NewLine
txt_log.Text += Environment.NewLine
txt_log.Text += "Errors:" + Environment.NewLine
txt_log.Text += "-------" + Environment.NewLine
txt_log.Text += errors + Environment.NewLine
Here is the result I get:
Output:
-------
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
The requested operation requires elevation (Run as administrator).
Errors:
-------
Any help would be appreciated
Continue reading...