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;
public static class PrinterControls
static extern bool AddPrinterConnection(string pName);
public static bool AddNetworkPrinter(string networkPrinterPath, ref string networkMessage)
result = AddPrinterConnection(networkPrinterPath);
networkMessage = "";
catch (Exception e)
result = false;
networkMessage = e.Message;
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.