我正在尝试从 c# 执行 vbscript,尽管我没有运行此脚本的权限,但 vbscript 始终成功运行。
编码:
//nswp is the User's password
foreach (char c in uspw)
{
password.AppendChar(c);
}
Process scriptProc = new Process();
scriptProc.StartInfo.RedirectStandardOutput = true;
scriptProc.StartInfo.RedirectStandardError = true;
scriptProc.StartInfo.Domain = "moia.gov.il";
scriptProc.StartInfo.ErrorDialog = true;
scriptProc.StartInfo.UserName = Globals.CURRENT_USER.user_name;
scriptProc.StartInfo.Password = password;
scriptProc.StartInfo.UseShellExecute = false;
scriptProc.StartInfo.FileName = @"cscript";
scriptProc.StartInfo.Arguments = "//B //Nologo " + pathSave;
scriptProc.Start();
scriptProc.WaitForExit();
scriptProc.Close();
当我手动执行这个 vbscript(通过双击文件图标)时,我应该得到一个权限错误。
如何在 c# 中捕获此错误并分别抛出异常。