To set the default printer in C# and VB.NET you can use the following snippet.

Sample C#

public static void SetDefaultPrinter(string printername)
{
	var type = Type.GetTypeFromProgID("WScript.Network");
	var instance = Activator.CreateInstance(type);
	type.InvokeMember("SetDefaultPrinter", System.Reflection.BindingFlags.InvokeMethod, null, instance, new object[] { printername });
}

Sample VB.NET

Public Shared Sub SetDefaultPrinter(ByVal printername As String)
        Dim type As var = Type.GetTypeFromProgID("WScript.Network")
        Dim instance As var = Activator.CreateInstance(type)
        type.InvokeMember("SetDefaultPrinter", System.Reflection.BindingFlags.InvokeMethod, Nothing, instance, New Object() {printername})
    End Sub

2 thought on “How to set the default printer in C# and VB.NET”

Leave a Reply