How to connect to network printer via C#
-
Hi, How can I connect a network printer to a user session via C#??? For example: I want to connect "\\intranet\phaser" to my current user session and show up as a network-based printer in my local Printers and Faxes folder. Chris
-
Hi, How can I connect a network printer to a user session via C#??? For example: I want to connect "\\intranet\phaser" to my current user session and show up as a network-based printer in my local Printers and Faxes folder. Chris
you can actually use WMI to install a network based printer. Here is an example of how it is done using VB script http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec06/hey1212.mspx[^] To access WMI in C#, you need to access the System.Management namespace. If you are stuck post back here again.
-
you can actually use WMI to install a network based printer. Here is an example of how it is done using VB script http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec06/hey1212.mspx[^] To access WMI in C#, you need to access the System.Management namespace. If you are stuck post back here again.
Thanks, but I got it. Here is what I did: [DllImport("winspool.drv")] public static extern bool AddPrinterConnection(string pName); [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(string printerName); bool result = AddPrinterConnection(@"\\server\printer"); bool resultdef = SetDefaultPrinter(@"\\server\printer"); Chris
-
Thanks, but I got it. Here is what I did: [DllImport("winspool.drv")] public static extern bool AddPrinterConnection(string pName); [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(string printerName); bool result = AddPrinterConnection(@"\\server\printer"); bool resultdef = SetDefaultPrinter(@"\\server\printer"); Chris
-
Thanks, but I got it. Here is what I did: [DllImport("winspool.drv")] public static extern bool AddPrinterConnection(string pName); [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(string printerName); bool result = AddPrinterConnection(@"\\server\printer"); bool resultdef = SetDefaultPrinter(@"\\server\printer"); Chris
Hi Chris, Thanks for the post! It worked for me. Just had to add namespace System.Runtime.InteropServices for DllImport i.e. using System.Runtime.InteropServices; Thanks again. Pallavi