1
我试图从ASP.NET页面上运行服务器上的批处理文件。批处理文件需要在某个用户帐户下运行才能成功。当试图以特定用户身份运行.bat文件时发生Win32Exception
我的代码来运行该批处理文件没有它特定帐户下运行工作正常,(当它在系统运行),但该批处理文件未能成功执行。
我需要能够做的是在服务器上的特定(管理员)帐户运行,但是当我添加代码这个帐户下运行,我得到一个异常:
系统.ComponentModel.Win32Exception (0X80004005):访问是在 System.Diagnostics.Process.StartWithCreateProcess(的ProcessStartInfo 的StartInfo)在 System.Diagnostics.Process.Start()
帐户definetely存在否认(这是该机器上唯一一个)并拥有管理权限。另外,如果我登录到物理机器并在该帐户下手动运行.bat文件,它可以正常工作。
这里是我的代码:
Process m_oProc = new Process();
ProcessStartInfo oInfo = new ProcessStartInfo(batchFileLocation);
oInfo.WorkingDirectory = Path.GetDirectoryName(batchFileLocation);
oInfo.UseShellExecute = false;
oInfo.RedirectStandardOutput = true;
oInfo.RedirectStandardError = true;
// ------ This code seems to cause the exception ------ //
string prePassword = "myadminpassword";
SecureString passwordSecure = new SecureString();
char[] passwordChars = prePassword.ToCharArray();
foreach (char c in passwordChars)
{
passwordSecure.AppendChar(c);
}
oInfo.UserName = "admin";
oInfo.Password = passwordSecure;
// ---------------------------------------------------- //
m_oProc.StartInfo = oInfo;
if (m_oProc.Start())
{
log.Info("Debug: Process has started successfully");
}
else
{
log.Error("Some error occured starting the process.");
}
谁能告诉我,我做错了什么?