请教各位VB朋友:如何运用VB代码更改打印机端口?某电脑有三个打印机端口(LPT1,LPT2,LPT3),如何运用VB代码改变打印机的端口。例如:ESPSON 300K打印机,端口号为:LPT1,通过VB程序将它改成端口号为:LPT2。能给实例就最好了。谢谢!

解决方案 »

  1.   

    我的e-Mail:  [email protected]
      

  2.   

    你查一下打印机方面的api函数,有点印象是有这个函数存在的
      

  3.   

    Dim P As Object
    For Each P In Printers
       If P.Port = "LPT2:" And P.DeviceName Like "*ESPSON 300K*" Then
          Set Printer = P
          Exit For
       End If
    Next P
      

  4.   

    准确点讲,Printer.port是只读属性
      

  5.   

    Set Printer = P
    仅仅是将 LPT2 上的 ESPSON 300K 设置为当前打印机。注意,不要试图更改 Port 属性。
      

  6.   

    OK!可能要用API函数SetPrinter了.
      

  7.   

    这个问题终于解决了,所用到的API函数有几个:OpenPrinter,ClosePrinter,GetPrinter,SetPrinter等。