Reputation: 19
System.Diagnostics.Process.Start C# authentication issues:
I am tying to write a coded UI test which can call external function (I know how to call a batch file but here I would like to call the exe using C# code)
Here is my code, I can bring up the log in window sometime. But it does not seem to authenticate.
public void Login()
{
Char[] input = "********".ToCharArray();
SecureString SecurePassword = new SecureString();
for (int idx = 0; idx < input.Length; idx++)
{
SecurePassword.AppendChar(input[idx]);
}
SecureString secure = SecurePassword;
string FileName = @"C:\\Program Files (x86)\\Helium\\Edition\\7.0\\Gateway\\UserShell.exe";
System.Diagnostics.Process.Start(FileName, "pAlan",secure,"");
}
Test method CodedUITest2.CodedUITestMethod1
threw exception:
System.ComponentModel.Win32Exception: The stub received bad data
Upvotes: 2
Views: 4872
Reputation: 11063
Try declaring a ProcessStartInfo variable, and don't use empty Domain Parameter. If you are not under domain, use the local machine name.
Try using also de runas verb to impersonate with that user:
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.UserName = "pAlan";
processStartInfo.Password = secure;
processStartInfo.Verb = "runas";
processStartInfo.Domain = MachineName;
Process.Start(processStartInfo);
Upvotes: 4