Цитата:
Цитата ferget
есть такое
echo ZZZZ > prn:
но вроде надо принтер настраивать »
|
перенаправить локальный порт (LPT1) на сетевой принтер через NET USE
если установлен .NET
батник "компилируется" в EXE (сабж)
читать дальше »
Код:
for /f "delims=" %%a in ('dir /s/a-d/b/od "%windir%\Microsoft.NET\Framework\vbc.exe"') do set "vbc=%%a"
(echo Imports System.IO
echo Imports System.Drawing.Printing
echo Imports System.Runtime.InteropServices
echo Module Test
echo ^<StructLayout^(LayoutKind.Sequential, CharSet:=CharSet.Unicode^)^> Structure DOCINFOW
echo ^<MarshalAs^(UnmanagedType.LPWStr^)^> Public pDocName As String
echo ^<MarshalAs^(UnmanagedType.LPWStr^)^> Public pOutputFile As String
echo ^<MarshalAs^(UnmanagedType.LPWStr^)^> Public pDataType As String
echo End Structure
echo ^<DllImport^("winspool.Drv",EntryPoint:="OpenPrinterW",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function OpenPrinter^(ByVal src As String,ByRef hPrinter As IntPtr,ByVal pd As Long^) As Boolean
echo End Function
echo ^<DllImport^("winspool.Drv",EntryPoint:="ClosePrinter",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function ClosePrinter^(ByVal hPrinter As IntPtr^) As Boolean
echo End Function
echo ^<DllImport^("winspool.Drv",EntryPoint:="StartDocPrinterW",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function StartDocPrinter^(ByVal hPrinter As IntPtr,ByVal level As Int32,ByRef pDI As DOCINFOW^) As Boolean
echo End Function
echo ^<DllImport^("winspool.Drv",EntryPoint:="EndDocPrinter",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function EndDocPrinter^(ByVal hPrinter As IntPtr^) As Boolean
echo End Function
echo ^<DllImport^("winspool.Drv",EntryPoint:="StartPagePrinter",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function StartPagePrinter^(ByVal hPrinter As IntPtr^) As Boolean
echo End Function
echo ^<DllImport^("winspool.Drv",EntryPoint:="EndPagePrinter",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function EndPagePrinter^(ByVal hPrinter As IntPtr^) As Boolean
echo End Function
echo ^<DllImport^("winspool.Drv",EntryPoint:="WritePrinter",SetLastError:=True,CharSet:=CharSet.Unicode,ExactSpelling:=True,CallingConvention:=CallingConvention.StdCall^)^> Public Function WritePrinter^(ByVal hPrinter As IntPtr,ByVal pBytes As IntPtr,ByVal dwCount As Int32,ByRef dwWritten As Int32^) As Boolean
echo End Function
echo Sub Main^(^)
echo Dim ps As New System.Drawing.Printing.PrinterSettings
echo Dim szPrinter As String = PS.PrinterName
echo Dim szString As String = My.Computer.Clipboard.GetText
echo Dim dwCount As Int32 = szString.Length^(^)
echo Dim pBytes As IntPtr = Marshal.StringToCoTaskMemAnsi^(szString^)
echo Dim di As DOCINFOW
echo di.pDocName="Clipboard RAW Printing"
echo di.pDataType = "RAW"
echo Dim hPrinter As IntPtr
echo Dim dwWritten As Int32
echo If OpenPrinter^(szPrinter,hPrinter,0^) Then
echo If StartDocPrinter^(hPrinter,1,di^) Then
echo If StartPagePrinter^(hPrinter^) Then
echo WritePrinter^(hPrinter,pBytes,dwCount,dwWritten^)
echo EndPagePrinter^(hPrinter^)
echo End If
echo EndDocPrinter^(hPrinter^)
echo End If
echo ClosePrinter^(hPrinter^)
echo End If
echo Marshal.FreeCoTaskMem^(pBytes^)
echo End Sub
echo End Module
)>"%~n0.tmp"
"%vbc%" "%~n0.tmp" /out:"%~n0.exe"
del "%~n0.tmp" "%~f0"& exit
источник: How to send raw data to a printer by using Visual Basic .NET
|