LPR命令无法从Windows服务打印pcl文件(现在是托盘应用程序) [英] LPR command to print pcl-file from windows service not working(Now a tray application)

查看:162
本文介绍了LPR命令无法从Windows服务打印pcl文件(现在是托盘应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找了一段时间,以寻求可能的解决方案和解释,但是我什么都找不到.

I've been looking around for a while for a possible solution and explanation, but I can't find anything really.

正在从Windows服务运行以下命令.如果直接在cmd中使用,则相同的命令也起作用. 它不会返回任何错误或其他任何事情.

The following command is being run from a windows service. The same command does function if used directly in cmd. It does not return any errors or anything else for that matter.

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C lpr.exe –S " + printerIP + " –P " + deviceName + " –o l " + fInfo.DirectoryName + @"\" + fInfo.Name;
    process.StartInfo = startInfo;
    process.Start();

这可能只是我所缺少的一些小事情,但是我看不到它.如果可以通过简单的替代方法使用lpr命令,我会喜欢的,但是我还没有看到任何东西.

It might just be some minor thing I'm missing, but I just can't see it. If it's possible to go around using the lpr-command with an easy alternative I'd love that, but I havent seen anything yet.

忘记添加我要发送到打印机的文件是pcl文件.

Forgot to add that the file I'm trying to send to the printer is a pcl file.

Edit2: 当我在未将隐藏"窗口样式和WaitForExit(5000)应用于流程的情况下运行该命令时,我似乎看不到任何编写的命令行-出现的只是空的命令提示符.

When I run the command without the Hidden windowstyle and WaitForExit(5000) applied to the process then I can't seem to see any commandline written - all that appears is the empty command prompt.

现在,我一直在做一些事情,我提出了以下建议:

Edit 3: Been toying a bit around with this now and I've come up with the following:

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "lpr";
    startInfo.Arguments = " –S " + printerIP + " –P " + deviceName + " –o l " + fInfo.DirectoryName + @"\" + fInfo.Name;
    process.StartInfo = startInfo;
    process.Start();

如果用户单击表单中的按钮来执行上述代码,则该代码将起作用.因此,我决定将代码更改为作为托盘应用程序运行,因为我认为这可以解决问题-但它似乎仍然拒绝运行.由触发的计时器或其他线程运行它是否会引起某种问题?还是与这些方法的权利有关?

The above code works if it is executed by a user clicking a button in a form. So I decided to change my code into running as a tray application, seeing as I thought this might solve the issues - yet it still seems to refuse being run. Could it be some sort of issue with it being run by a triggered timer or another thread? Or perhaps something to do with the rights of those methods?

推荐答案

将代码更改为此:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C C:\windows\Sysnative\lpr.exe –S " + printerIP + " –P " + deviceName + " –o l " + fInfo.DirectoryName + @"\" + fInfo.Name;
process.StartInfo = startInfo;
process.Start();

问题是您试图从32位cmd.exe应用程序访问64位应用程序(lpr).简单的解决方案是使用sysnative目录.

The issue is that you are trying to access a 64 bit application (lpr) from a 32 bit cmd.exe application. The simple solution is to use the sysnative directory.

http://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm

在Windows资源管理器中,"Sysnative"文件夹是不可见的 启动Windows资源管理器并打开硬盘上的Windows文件夹, 您可能会注意到未显示Sysnative文件夹.主要原因 这是因为Windows资源管理器是64位程序(在 64位Windows),并且仅可见Sysnative文件夹,并且 可从32位软件访问.如果64位软件需要访问 Windows中的64位系统文件夹,唯一的选择是使用 System32文件夹名称(例如:C:\ Windows \ System32).

The 'Sysnative' folder is invisible in Windows Explorer If you start Windows Explorer and open the Windows folder on your hard disk, you may notice that the Sysnative folder is not shown. The main reason to this is that Windows Explorer is a 64-bit program (when run in a 64-bit Windows), and the Sysnative folder is only visible and accessible from 32-bit software. If 64-bit software need access to the 64-bit system folder in Windows, the only option is to use the System32 folder name (for example: C:\Windows\System32).

使用系统"文件夹将帮助您从以下位置访问64位工具 32位代码64位Windows中的某些工具仅在64位中存在 版本;没有可用的32位版本.还有一些工具 位于64位System32文件夹中.一个例子是nbtstat 用于解决NetBIOS名称解析问题的工具 问题.如果您尝试从32位代码运行nbtstat工具(对于 来自应用程序或脚本的示例),并使用类似 C:\ Windows \ System32,您将收到找不到文件"错误.文件 找不到;尽管Windows资源管理器显示nbtstat 程序文件实际上位于C:\ Windows \ System32文件夹中.
解决此问题(有点令人困惑)的方法是将 当您要运行虚拟Sysnative文件夹时,在文件夹路径中 工具.例如:C:\ Windows \ Sysnative \ nbtstat.exe 上面的文件路径将使您可以从以下位置访问64位nbtstat工具: 32位应用程序或32位脚本.我们建议您阅读 本文/博客文章(在Scottie的Tech.Info上)以获取更多详细信息 关于这个.

Using the 'Sysnative' folder will help you access 64-bit tools from 32-bit code Some tools in a 64-bit Windows only exist in a 64-bit version; there is no 32-bit version available. And some of these tools are located in the 64-bit System32 folder. One example is the nbtstat tool that is used to help troubleshoot NetBIOS name resolution problems. If you try to run the nbtstat tool from 32-bit code (for example from an application or from script) and use a path like C:\Windows\System32, you will get a "File not found" error. The file can not be found; although Windows Explorer shows that the nbtstat program file actually is located in the C:\Windows\System32 folder.
The solution to this (somewhat confusing) problem is to include the virtual Sysnative folder in the folder path when you want to run the tool. For example like this: C:\Windows\Sysnative\nbtstat.exe The file path above will give you access to the 64-bit nbtstat tool from a 32-bit application or from a 32-bit script. We recommend you to read this article / blog post (at Scottie’s Tech.Info) to get more details about this.

这篇关于LPR命令无法从Windows服务打印pcl文件(现在是托盘应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆