Hi
I'm trying to create a program which starts another one. Because the target application is located on our domain and the pc it must run on isnt, I have to pass the appropiate user credentials but no success. What am I doing wrong? The code I'm using is:
Public Sub ShellandWait(ByVal ProcessPath As String, ByVal ProcessArgs As String)
Dim objProcess As System.Diagnostics.Process
Try
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.Arguments = ProcessArgs
objProcess.StartInfo.UserName = "accountname"
Dim pw As New System.Security.SecureString
pw.Clear()
For Each ch As Char In "password"
pw.AppendChar(ch)
Next
objProcess.StartInfo.Password = pw
objProcess.StartInfo.Domain = "mydomain"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
objProcess.StartInfo.UseShellExecute = False
objProcess.Start()
'Wait until the process passes back an exit code
objProcess.WaitForExit()
'Free resources associated with this process
objProcess.Close()
Catch
MessageBox.Show("Could not start process " & ProcessPath, "Error")
End Try
End Sub
cheers
Leo
I'm trying to create a program which starts another one. Because the target application is located on our domain and the pc it must run on isnt, I have to pass the appropiate user credentials but no success. What am I doing wrong? The code I'm using is:
Public Sub ShellandWait(ByVal ProcessPath As String, ByVal ProcessArgs As String)
Dim objProcess As System.Diagnostics.Process
Try
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.Arguments = ProcessArgs
objProcess.StartInfo.UserName = "accountname"
Dim pw As New System.Security.SecureString
pw.Clear()
For Each ch As Char In "password"
pw.AppendChar(ch)
Next
objProcess.StartInfo.Password = pw
objProcess.StartInfo.Domain = "mydomain"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
objProcess.StartInfo.UseShellExecute = False
objProcess.Start()
'Wait until the process passes back an exit code
objProcess.WaitForExit()
'Free resources associated with this process
objProcess.Close()
Catch
MessageBox.Show("Could not start process " & ProcessPath, "Error")
End Try
End Sub
cheers
Leo