I'm trying to pass a string from vb.net into a command prompt window. In the end I want to use runas and use a password that was supplied earlier when logging into the application as the password. Basically I want to run the runas command, then type the password into the window (or supply it to cmd in some way)
Public Sub runCmd(ByVal pass As String, ByVal command As String, ByVal arguments As String, ByVal permanent As Boolean)
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
pi.FileName = "cmd.exe"
pi.Verb = "runas"
p.StartInfo = pi
p.Start()
End Sub
This is the updated code where I get the directory error
Public Sub runCmd(ByVal pass As String, ByVal user As String, ByVal domainName As String, ByVal command As String, ByVal arguments As String, ByVal permanent As Boolean)
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
pi.FileName = "cmd.exe"
pi.Verb = "runas"
pi.UserName = user
pi.Domain = domainName
pi.Password = getSecureString(pass)
p.StartInfo = pi
pi.UseShellExecute = False
p.Start()
End Sub