Following is my code:
private static bool Register(string fullFileName, string username, SecureString password)
{
var isRegistered = false;
using (var process = new Process())
{
var startInfo = process.StartInfo;
startInfo.FileName = "regsvr32.exe";
startInfo.Arguments = string.Format("/s {0}", fullFileName);
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.ErrorDialog = true;
process.EnableRaisingEvents = true;
startInfo.Verb = "runas";
startInfo.UserName = username;
startInfo.Password = password;
try
{
isRegistered = process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message );
}
}
return isRegistered;
}
}
- If the username and passord are wrong for example, it will enter the catch part and I can return false - FINE
If I am commenting out the following:
startInfo.Verb = "runas"; startInfo.UserName = username; startInfo.Password = password;
then it will not work since it need to be registered as admin. but the isRegistered will be set to true.
How can I know that it doesn't work?
Note: I am running it in silence mode so the user can't see the prompt. The error prompt is displayed when working in non-silent mode.