运行 ASP.NET 中的 PSEXEC 进程作为不同的用户
Run PSEXEC process in ASP.NET as different user
我正在尝试使用 psExec 从我在 IIS 服务器上发布的 ASP Web 应用程序连接到某些服务器,启动应用程序并获取输出。
当我尝试在不设置凭据的情况下启动进程时,出现此错误:
Access is denied
但如果我像管理员一样操作,我只会得到输出、错误和异常变量的空字段。此外,当我使用 visual studio 从我的本地电脑执行此操作时,它可以正常工作。
我做错了什么?这是我的代码:
try
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866);
p.StartInfo.StandardErrorEncoding = Encoding.GetEncoding(866);
p.StartInfo.FileName = @"C:\inetpub\wwwroot\Monitoring\bin\PsExec.exe";
server = "dp-next.b42";
p.StartInfo.Arguments = @" \" + server + " \"c:\program files\omniback\bin\omnirpt.exe\" -report list_sessions -timeframe 12 12";
p.StartInfo.UserName = "admin";
p.StartInfo.Domain = "domain";
string pass = "password";
SecureString s = new SecureString();
foreach(char c in pass)
{
s.AppendChar(c);
}
p.StartInfo.Password = s;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
output = output + p.ProcessName;
//output = p.StandardOutput.ReadToEnd();
while ((res = p.StandardOutput.ReadLine()) != null)
{
i++;
output = output + res;
}
errors = p.StandardError.ReadToEnd();
p.Close();
}
catch (Exception ex)
{
exe = ex.ToString();
}
我曾经不得不开发一些非常相似的东西。这是我所做的。
而不是使用:
p.StartInfo.UserName = "admin";
p.StartInfo.Domain = "domain";
p.StartInfo.Password = s;
我将用户名和密码直接放在 PsExec 命令参数中(分别使用 -u
和 -p
)。你的情况:
p.StartInfo.Arguments = @" \" + server + " -u YOUR_DOMAIN\YOUR_USERNAME -p YOUR_PASSWORD \"c:\program files\omniback\bin\omnirpt.exe\" -report list_sessions -timeframe 12 12";
有关 PsExec 用法的更多信息 here。
我正在尝试使用 psExec 从我在 IIS 服务器上发布的 ASP Web 应用程序连接到某些服务器,启动应用程序并获取输出。
当我尝试在不设置凭据的情况下启动进程时,出现此错误:
Access is denied
但如果我像管理员一样操作,我只会得到输出、错误和异常变量的空字段。此外,当我使用 visual studio 从我的本地电脑执行此操作时,它可以正常工作。
我做错了什么?这是我的代码:
try
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866);
p.StartInfo.StandardErrorEncoding = Encoding.GetEncoding(866);
p.StartInfo.FileName = @"C:\inetpub\wwwroot\Monitoring\bin\PsExec.exe";
server = "dp-next.b42";
p.StartInfo.Arguments = @" \" + server + " \"c:\program files\omniback\bin\omnirpt.exe\" -report list_sessions -timeframe 12 12";
p.StartInfo.UserName = "admin";
p.StartInfo.Domain = "domain";
string pass = "password";
SecureString s = new SecureString();
foreach(char c in pass)
{
s.AppendChar(c);
}
p.StartInfo.Password = s;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
output = output + p.ProcessName;
//output = p.StandardOutput.ReadToEnd();
while ((res = p.StandardOutput.ReadLine()) != null)
{
i++;
output = output + res;
}
errors = p.StandardError.ReadToEnd();
p.Close();
}
catch (Exception ex)
{
exe = ex.ToString();
}
我曾经不得不开发一些非常相似的东西。这是我所做的。
而不是使用:
p.StartInfo.UserName = "admin";
p.StartInfo.Domain = "domain";
p.StartInfo.Password = s;
我将用户名和密码直接放在 PsExec 命令参数中(分别使用 -u
和 -p
)。你的情况:
p.StartInfo.Arguments = @" \" + server + " -u YOUR_DOMAIN\YOUR_USERNAME -p YOUR_PASSWORD \"c:\program files\omniback\bin\omnirpt.exe\" -report list_sessions -timeframe 12 12";
有关 PsExec 用法的更多信息 here。