[英]How to know that an automated regsvr32 doesn't work
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 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. 但是isRegistered将设置为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. 在非静默模式下显示错误提示。
After the process.WaitForExit()
, you should check the process's exit code. 在process.WaitForExit()
,您应该检查进程的退出代码。
Process.ExitCode
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode%28v=vs.110%29.aspx
It is 0
if all succeeded. 如果全部成功,则为0
。 Non-zero if failed. 如果失败,则非零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.