Insert network printers automatically

In my current upgrade project I need to upgrade a solution I did for Classic NAV where I used the “‘Windows Script Host Object Model’.WshNetwork” Automation object to add a network printer automatically.

I looked a round and did not find any dotnet object capable of adding a network printer.  However, there was a c# code I found that was able to do this.  So, I created a NAV Add-in with this code

[code lang=”csharp”]using System;
using System.Runtime.InteropServices;

namespace NAVPrinterAdd_in
public static class PrinterControls
static extern bool AddPrinterConnection(string pName);

public static bool AddNetworkPrinter(string networkPrinterPath, ref string networkMessage)
bool result;
result = AddPrinterConnection(networkPrinterPath);
networkMessage = "";
catch (Exception e)
result = false;
networkMessage = e.Message;
return result;


The Add-in is attached. Next I created a Codeunit in NAV.


And used in Codeunit 1, FindPrinter trigger.


Now I can make sure that the correct printer is installed for the client and also for the server when printing from NAS session.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.