Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows services 使用GhostScript从Windows服务打印PDF-如何诊断权限问题_Windows Services_User Permissions_Diagnostics - Fatal编程技术网

Windows services 使用GhostScript从Windows服务打印PDF-如何诊断权限问题

Windows services 使用GhostScript从Windows服务打印PDF-如何诊断权限问题,windows-services,user-permissions,diagnostics,Windows Services,User Permissions,Diagnostics,我有一个用C写的服务。运行以下代码: public static bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFileName) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.Arguments = $@"-dPrinted -dNoCancel=true -dBAT

我有一个用C写的服务。运行以下代码:

public static bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFileName)
{
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.Arguments = $@"-dPrinted -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies={numberOfCopies} -sDEVICE=mswinpr2 -sOutputFile=""\\spool\{printerName}"" ""{pdfFileName}""";

    startInfo.FileName = Path.Combine(ghostScriptPath, "gswin64c.exe");
    startInfo.UseShellExecute = false;
    startInfo.CreateNoWindow = true;
    startInfo.RedirectStandardError = true;
    startInfo.RedirectStandardOutput = true;

    Process process = Process.Start(startInfo);

    Console.WriteLine(process.StandardError.ReadToEnd() + process.StandardOutput.ReadToEnd());

    process.WaitForExit(30000);
    if (process.HasExited == false) process.Kill();


    return process.ExitCode == 0;
}
在Windows服务之外,它可以正常工作。 在服务内部,当作为本地系统运行时,GhostScript开始运行,但在没有任何输出的情况下超时

在做了一些修改之后,我最终将该服务切换为“作为网络服务运行”,并将“网络服务”设置为放置服务exe和GhostScript exe的文件夹的所有者(在此之前,我收到了拒绝访问错误),现在该服务运行正常

我的问题是-为什么网络服务可以在本地系统不能的地方工作?我认为本地系统有更多的特权。还有,我怎样才能获得更多关于实际问题的信息?我已经找到了一个解决办法,但这只是在黑暗中的一个幸运的机会。我不知道真正的问题是什么

更多信息:
运行Windows 10 64位,并使用GhostScript v9.29,您需要在专用于该服务的本地用户帐户下运行该服务。 您还需要在列表中登录该用户一次,以便填充打印机列表