ProcessStartInfo.Password is not a simple string that you can write and assign to a property. You need an instance of SecureString , and SecureString cannot be created by passing a simple string to its constructor. Obviously, the OS does not have an API or method that allows an unreliable program to retrieve the password of the current user (this will be the biggest security error ever heard).
So, in my opinion, you have only one option left. Ask your user to enter the password again, and the result should be converted to SecureString
This example is an extension method for the string class that I saw here
using System.Security; // ... public static SecureString ConvertToSecureString(this string password) { if (password == null) throw new ArgumentNullException("password"); unsafe { fixed (char* passwordChars = password) { var securePassword = new SecureString(passwordChars, password.Length); securePassword.MakeReadOnly(); return securePassword; } } }
you can use it to convert the password entered by your user and start the process
using(frmGetPassword fgp = new frmGetPassword()) { if(DialogResult.OK == fgp.ShowDialog()) { SecureString ss = fgp.Password.ConvertToSecureString(); var processInfo = new ProcessStartInfo { WorkingDirectory = workingDirectory, FileName = "a name", UserName = loggedUserName, Password = ss, Domain = userNameDomain, UseShellExecute = false, }; Process.Start(processInfo); } }
Steve source share