Hi Ken,
In Windows NT/2000/XP, you should use AddPrinterConnection().
You can get more information in my reply in the post: "Does .Netframework
have a way to add a network printer"
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.
--------------------
| Content-Class: urn:content-classes:message
| From: "Ken" <
[email protected]>
| Sender: "Ken" <
[email protected]>
| References: <
[email protected]>
<#
[email protected]>
| Subject: Re: AddPrinter using C#
| Date: Fri, 1 Aug 2003 08:24:06 -0700
| Lines: 141
| Message-ID: <
[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: quoted-printable
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcNYQPJkVi2sbwtIQ8+XzsyNmovLTQ==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:173567
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hello Mattias,
| I took your suggestion , but I still cannot see the
| printer on my machine. Here is what I am using:
| Any suggestions?
| Thank You in Advance for All Your Help,
| Ken
| [DllImport("winspool.drv",CharSet=CharSet.Auto)]
| private static extern IntPtr AddPrinter(string myserver,
| uint dwLevel, ref PRINTER_INFO_2 pi );
| private void menuItem4_Click(object sender,
| System.EventArgs e)
| {
| string mynull;
| mynull = null;
| IntPtr mystrptr = new IntPtr(0);
| bool mysend;
| IntPtr mysend2;
| PRINTER_INFO_2 pi = new
| PRINTER_INFO_2();
| string myservername;
| myservername = "blahblah"
|
| pi.pServerName = "\\\\" +
| myservername ;
| pi.pPrinterName = "\\\\" +
| myservername + "\\" + "CN-3-NCA" ;
| pi.pShareName = "CN-3-NCA";
| pi.pPortName
| = "123.123.123.27

rint";
| pi.pDriverName = "Cannon iR2200-
| 3300 PCL6";
| pi.pComment = "No Comment";
| pi.pLocation = "3rd Floor North
| Alcove Copy Center";
| pi.pDevMode = mystrptr;
| pi.pSepFile = "";
| pi.pPrintProcessor = "WinPrint";
| pi.pDatatype = "RAW";
| pi.pParameters = "";
| pi.pSecurityDescriptor =
| mystrptr;
| //pi.Attributes = mystrptr;
| //pi.Priority = mystrptr;
| //pi.DefaultPriority = mystrptr;
| //pi.StartTime = mystrptr;
| //pi.UntilTime = mystrptr;
| //pi.Status = mystrptr;
| //pi.cJobs = mystrptr;
| //pi.AveragePPM = mystrptr;
| mysend2 = AddPrinter(mynull,2, ref
| pi);
| }
|
| [StructLayout(LayoutKind.Sequential,
| CharSet=CharSet.Auto)]
|
| private class PRINTER_INFO_2
| {
| public string pServerName;
| public string
| pPrinterName;
| public string pShareName;
| public string pPortName;
| public string pDriverName;
| public string pComment;
| public string pLocation;
| public IntPtr pDevMode;
| public string pSepFile;
| public string
| pPrintProcessor;
| public string pDatatype;
| public string pParameters;
| public IntPtr
| pSecurityDescriptor;
| public uint Attributes;
| public uint Priority;
| public uint
| DefaultPriority;
| public uint StartTime;
| public uint UntilTime;
| public uint Status;
| public uint cJobs;
| public uint AveragePPM;
| }
| >-----Original Message-----
| >Ken,
| >
| >Try this
| >
| >[DllImport("winspool.drv", CharSet=CharSet.Auto)]
| >static extern IntPtr AddPrinter(string pName, uint Level,
| [In] ref
| >PRINTER_INFO_2 pPrinter);
| >
| >[StructLayout(LayoutKind.Sequential,
| CharSet=CharSet.Auto)]
| >struct PRINTER_INFO_2
| >{
| > public string pServerName,
| > pPrinterName,
| > pShareName,
| > pPortName,
| > pDriverName,
| > pComment,
| > pLocation;
| > public IntPt pDevMode;
| > public string pSepFile,
| > pPrintProcessor,
| > pDatatype,
| > pParameters;
| > public IntPtr pSecurityDescriptor;
| > public uint Attributes,
| > Priority,
| > DefaultPriority,
| > StartTime,
| > UntilTime,
| > Status,
| > cJobs,
| > AveragePPM;
| >}
| >
| >
| >
| >Mattias
| >
| >--
| >Mattias Sjögren [MVP] mattias @ mvps.org
| >
http://www.msjogren.net/dotnet/
| >Please reply only to the newsgroup.
| >.
| >
|