首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将数据发送到windows XP上的LPT

将数据发送到windows XP上的LPT
EN

Stack Overflow用户
提问于 2011-01-02 22:08:06
回答 1查看 3.3K关注 0票数 0

我想将数据发送到LPT1上的打印机,并尝试使用this,但CreateFile返回-1 (系统无法从HRESULT0x80070002找到文件specified.Exception )。如何打开LPT1端口并将数据发送到?我在XP和之后的64位win7上尝试这个,因为从我读到的在64位win7中使用LPT是一个小问题,或者我应该说64位的问题:)

因为这是我今年的第一篇文章:祝大家新年快乐。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-02 22:48:37

您可以尝试以下操作。适用于文本模式。

‘'net’显示以下内容:

代码语言:javascript
复制
Share name   Resource                        Remark

-------------------------------------------------------------------------------
IPC$                                         Remote IPC
D$           D:\                             Default share
print$       C:\WINDOWS\system32\spool\drivers
                                             Printer Drivers
wwwroot$     c:\inetpub\wwwroot              Used for file share access to web
C$           C:\                             Default share
ADMIN$       C:\WINDOWS                      Remote Admin
SharedDocs   C:\DOCUMENTS AND SETTINGS\ALL USERS\DOCUMENTS

Printer2     IP_192.168.115.227     Spooled  HP LaserJet 2200 Series PS (MS)
TEST         LPT1:                  Spooled  Microsoft XPS Document Writer
The command completed successfully.

下面是代码

代码语言:javascript
复制
using System;
using System.IO;

namespace SimplePrinting
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class SimplePrinting
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            string printingTaskFileName = Path.GetTempFileName(); // file in %temp%

            System.IO.FileStream printingTaskFile;
            System.IO.StreamWriter printingTaskStream;

            printingTaskFile = new System.IO.FileStream(printingTaskFileName, FileMode.Append);
            printingTaskStream = new System.IO.StreamWriter(printingTaskFile, System.Text.Encoding.Default);

            printingTaskStream.Write("some content here");
            printingTaskStream.Flush();
            printingTaskStream.Close();

            File.Copy(printingTaskFileName, @"\\127.0.0.1\TEST", true); // also can be \\127.0.0.1\PNT5 or smth like that
            File.Delete(printingTaskFileName);
        }
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4578699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档