Yes, it is,
Thanks very much.
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Willy Denoyette [MVP]" <
[email protected]>
| References: <
[email protected]>
<7D#Y3Z#
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: Does .Netframework have a way to add a network printer
| Date: Thu, 7 Aug 2003 12:09:23 +0200
| Lines: 121
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: d5e01079.kabel.telenet.be 213.224.16.121
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:174824
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Note that you should call Marshal.GetLastWin32Error() instead of
GetLastError() , the result of GetLastError() is unreliable in
| PInvoke scenarios. (see:
http://blogs.gotdotnet.com/anathan/CategoryView.aspx/Interop)
|
| Willy.
|
| Jeffrey Tan[MSFT] wrote:
| || Hi,
| ||
| || To use AddPrinter() fucntion to add a new printer:
| ||
| || using System;
| || using System.Runtime .InteropServices ;
| ||
| || namespace addprint
| || {
| || class Class1
| || {
| || [DllImport("winspool.drv", CharSet=CharSet.Auto)]
| || static extern int AddPrinter(string pName, uint Level, [In] ref
| || PRINTER_INFO_2 pPrinter);
| ||
| || [DllImport("KERNEL32.dll")]
| || static extern void ZeroMemory(ref PRINTER_INFO_2 pPrinter,int
| || length);
| ||
| || [DllImport("winspool.drv")]
| || static extern int ClosePrinter(int hPrinter);
| ||
| || [DllImport("kernel32.dll")]
| || public static extern int GetLastError();
| ||
| || [STAThread]
| || static void Main(string[] args)
| || {
| || PRINTER_INFO_2 pi2=new PRINTER_INFO_2 ();
| || int hPrinter;
| || int herror;
| || ZeroMemory(ref pi2,Marshal.SizeOf(pi2));
| || pi2.pPrinterName = "HP LaserJet 8100 Series PCL6";
| || pi2.pPortName = "\\\\sha-prn-01\\2017hp8100";
| || pi2.pDriverName = "HP LaserJet 8100 Series PCL6";
| || pi2.pPrintProcessor = "WinPrint";
| || hPrinter = AddPrinter("", 2, ref pi2);
| || if(hPrinter==0)
| || {
| || herror=GetLastError();
| || }
| || ClosePrinter(hPrinter);
| || }
| ||
| || [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
| || struct PRINTER_INFO_2
| || {
| || public string pServerName,
| || pPrinterName,
| || pShareName,
| || pPortName,
| || pDriverName,
| || pComment,
| || pLocation;
| || public IntPtr pDevMode;
| || public string pSepFile,
| || pPrintProcessor,
| || pDatatype,
| || pParameters;
| || public IntPtr pSecurityDescriptor;
| || public uint Attributes,
| || Priority,
| || DefaultPriority,
| || StartTime,
| || UntilTime,
| || Status,
| || cJobs,
| || AveragePPM;
| || }
| || }
| || }
| ||
| || It works well on my machine.
| ||
| || Best regards,
| ||
| || Jeffrey Tan
| || Microsoft Online Partner Support
| || Get Secure! -
www.microsoft.com/security
| || This posting is provided "as is" with no warranties and confers no
| || rights.
| ||
| || --------------------
| ||| From: "Willy Denoyette [MVP]" <
[email protected]>
| ||| References: <
[email protected]>
| ||| <7D#Y3Z#
[email protected]> Subject: Re: Does
| ||| .Netframework have a way to add a network printer
| ||| Date: Wed, 6 Aug 2003 12:16:16 +0200
| ||| Lines: 13
| ||| X-Priority: 3
| ||| X-MSMail-Priority: Normal
| ||| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| ||| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| ||| Message-ID: <
[email protected]>
| ||| Newsgroups: microsoft.public.dotnet.languages.csharp
| ||| NNTP-Posting-Host: d5e01079.kabel.telenet.be 213.224.16.121
| ||| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| ||| Xref: cpmsftngxa06.phx.gbl
| ||| microsoft.public.dotnet.languages.csharp:174555 X-Tomcat-NG:
| ||| microsoft.public.dotnet.languages.csharp
| |||
| ||| Jeffrey Tan[MSFT] wrote:
| ||||| Hi Ken,
| |||||
| ||||| In Window NT/2000/XP, you should use AddPrinterConnection() API
| ||||| function to add a printer.
| |||
| ||| I guess Ken want's to add a new printer to the system, not to
| ||| connect a user to an existing printer.
| |||
| ||| Ken, can you please post a repro, or at least that part that fails.
| |||
| ||| Willy.
|
|
|