我正在尝试通过Process.Start手动打印PDF,但它无法在IIS中运行。我在Windows窗体应用程序中复制了相同的代码并且工作正常。我已经尝试授予“网络服务”用户权限(我的应用程序池具有网络服务权限)。我也按照这里的步骤: IIS7 does not start my Exe file by Process Start
string file = @"C:\test.pdf";
string printer = "TestPrinter";
string processFilename = Microsoft.Win32.Registry.LocalMachine
.OpenSubKey("Software")
.OpenSubKey("Microsoft")
.OpenSubKey("Windows")
.OpenSubKey("CurrentVersion")
.OpenSubKey("App Paths")
.OpenSubKey("AcroRd32.exe")
.GetValue(String.Empty).ToString();
var info = new ProcessStartInfo();
info.FileName = processFilename;
info.Arguments = string.Format("/h /t \"{0}\" \"{1}\"", file, printer);
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
int counter = 0;
while (!p.HasExited)
{
System.Threading.Thread.Sleep(1000);
counter += 1;
if (counter == 5) break;
}
if (!p.HasExited)
{
p.CloseMainWindow();
p.Kill();
}