通过提示符配置打印机的重定向端口 [英] Configuring a printer's redirect port via prompt

查看:223
本文介绍了通过提示符配置打印机的重定向端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试为我用Java编写的程序创建一个安装程序,以实现GhostScript,该程序创建一个将文件发送到的虚拟打印机.然后,我的程序读取文件并进行相应的管理.但是,我必须手动配置RedMon重定向端口(RPT1 :),并使用该端口并以.jar文件作为参数来手动创建新打印机:

I've been trying to create an installer for a program I wrote in Java, implementing GhostScript, that creates a virtual printer where the file is sent to. My program then reads the files and manages it accordingly. However, I had to manually configure the RedMon Redirect Port (RPT1:) and manually created a new printer, using that port, taking as arguments the .jar file:

在打印机端口上配置的参数:

Arguments configured on the printer's port:

我能够通过NSIS(我用来创建安装程序的程序)创建新打印机,如下所示:

I was able to create a new printer via NSIS (the program I'm using to create the installer) like so:

Exec 'cscript "C:\Windows\System32\Printing_Admin_Scripts\pt-BR\prnport.vbs" ^ -a -r RPT1:'
ExecWait 'rundll32 printui.dll,PrintUIEntry /if /f "$INSTDIR\ghostpdf.inf"^ /r "RPT1:" /m "Ghostscript PDF" /b "Impressora SPE" /u /Y'

有没有一种方法可以通过命令来配置端口?如果可能的话,我想为我的程序创建一个单独的端口(当前我正在使用默认的RedMon端口),而且还要在安装时将Java参数传递给它,因此最终用户不必手动包括这些论点.我到处都看过,但是我发现的每本指南和文章都是手动完成的.

Is there a way to do the same, via commands, for configuring ports? If possible, I'd like to create a separate port for my program (currently I'm using the default RedMon port), but also pass the Java arguments to it on installation, so the end user doesn't have to manually include these arguments. I've looked everywhere, but every guide and article I found had it done manually.

感谢您的帮助!

推荐答案

花了一些时间,但我终于找到了使用RedMon设置新打印机端口所需的命令,并想在这里共享它.更少的人很难找到它.

It took me a bit of digging, but I finally found the command required to setup a new printer port using RedMon, and figured I'd share it here so less people have a hard time finding it.

rundll32 "REDMONPATH\redmon32.dll", RedMonConfigurePort Port="PORT:" Command="JAVA" Arguments="-jar ""JAR"" ""C:\Program Files (x86)\gs\gs9.21\bin\gswin32c -I\""C:\Program Files (x86)\gs\gs9.21\lib\"" -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sPAPERSIZE=a4 -r300"""

其中REDMONPATH是RedMon安装文件夹的路径,PORT是端口的名称,JAVA是java.exe的路径,而JAR是.jar文件的路径.不要保留双引号,这是我们通过命令传递引号的方式.但是,您必须在RedMon安装文件夹上运行此命令.另外,您必须以管理员身份运行,否则可能会收到错误并错误地认为自己做错了什么.就我而言,使用NSIS,这是完整的命令行:

Where REDMONPATH is the path to your RedMon installation folder, PORT is your port's name, JAVA is your path to the java.exe, and JAR is the path to your .jar file. DO keep the double quotes, it's how we pass quotes via commands. You must run this command on the RedMon installation folder, though. Also, you MUST run as an administrator, otherwise you might get an error and wrongly assume you did something wrong. In my case, using NSIS, this is the full command line:

ExecWait 'rundll32 "$INSTDIR\redmon\redmon32.dll", RedMonConfigurePort Port="SPE:" Command="C:\Program Files (x86)\Java\jre1.8.0_144\bin\java.exe" Arguments="-jar ""C:\Program Files (x86)\Impressora SPE\ImpressoraSPE.jar"" \""C:\Program Files (x86)\gs\gs9.21\bin\gswin32c -l \""C:\Program Files (x86)\gs\gs9.21\lib\"" -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sPAPERSIZE=a4 -r300"""'

之后,您可以正常使用新端口安装新打印机:

After that, you can install your new printer using the new port normally:

ExecWait 'rundll32 printui.dll,PrintUIEntry /if /f "$INSTDIR\ghostpdf.inf" /r "PORT:" /m "Ghostscript PDF" /b "PRINTER_NAME" /u /Y'`

如果您尝试从命令提示符而不是NSIS运行此命令,那么您所要做的就是删除"ExecWait"位和命令周围的单引号.还要用相应的完整路径替换"$ INSTDIR \ something".

If you're trying to run this from the command prompt and not NSIS, all you gotta do is remove the "ExecWait" bit and the single quotes around the command. Also replace "$INSTDIR\something" by the corresponding full path.

如果其他人在这个问题上需要进一步的帮助,看到我个人对此很困难,请随时在这里问他们,我会尽力帮助您!

If anyone else needs further help with this subject, seeing that I personally had quite a hard time with it, feel free to ask them here and I'll try my best to help!

编辑:对于不断进行的编辑,我深表歉意,只是确保在我在不同版本的Windows中测试这些说明时,请保留对大多数人有用的说明.

I apologize for the constant edits, just making sure to leave the instructions that help the most people as I test these in different version of Windows.

这篇关于通过提示符配置打印机的重定向端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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