diff --git a/PrinterDebug.Console/PrinterDebug.Console.csproj b/PrinterDebug.Console/PrinterDebug.Console.csproj new file mode 100644 index 0000000..da666d0 --- /dev/null +++ b/PrinterDebug.Console/PrinterDebug.Console.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {74AAF6F3-E538-4295-81A0-57634C547B07} + Exe + Properties + PrinterDebug.Console + PrinterDebug.Console + v4.7.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + diff --git a/PrinterDebug.Console/Program.cs b/PrinterDebug.Console/Program.cs new file mode 100644 index 0000000..43615d7 --- /dev/null +++ b/PrinterDebug.Console/Program.cs @@ -0,0 +1,87 @@ +using System.Drawing.Printing; +using System.Linq; +using System.Printing; + +namespace PrinterDebug.Console +{ + public static class Program + { + public static void Main(string[] args) + { + System.Console.WriteLine("Use the following parameters"); + System.Console.WriteLine("-l - Print all local printers"); + System.Console.WriteLine("-a - Print all printers"); + System.Console.WriteLine("-d - Print printers of System.Drawing"); + System.Console.WriteLine("-v - Verbose information"); + + var verbose = args.Contains("-v"); + + if (args.Contains("-l")) + { + GetLocalPrinters(verbose); + System.Console.WriteLine("------"); + } + + if (args.Contains("-a")) + { + GetAllPrinters(verbose); + System.Console.WriteLine("------"); + } + + if (args.Contains("-d")) + { + GetAllSystemDrawingPrinters(); + System.Console.WriteLine("------"); + } + } + + private static void GetAllSystemDrawingPrinters() + { + System.Console.WriteLine("System Drawing Printers:"); + foreach (var printer in PrinterSettings.InstalledPrinters) + { + System.Console.WriteLine($"Name: {printer}"); + } + } + + private static void GetLocalPrinters(bool verbose) + { + System.Console.WriteLine("Local Printers:"); + using (var localSystem = new LocalPrintServer()) + { + foreach (var queue in localSystem.GetPrintQueues()) + { + System.Console.WriteLine($"Name: {queue.Name}"); + if (verbose) + { + System.Console.WriteLine($"Fullname: {queue.FullName}"); + System.Console.WriteLine($"Location: {queue.Location}"); + System.Console.WriteLine($"IsShared: {queue.IsShared}"); + System.Console.WriteLine($"IsDirect: {queue.IsDirect}"); + System.Console.WriteLine("---"); + } + } + } + } + + private static void GetAllPrinters(bool verbose) + { + System.Console.WriteLine("All Printers:"); + using (var localSystem = new PrintServer()) + { + foreach (var queue in localSystem.GetPrintQueues()) + { + System.Console.WriteLine($"Name: {queue.Name}"); + if (verbose) + { + System.Console.WriteLine($"Fullname: {queue.FullName}"); + System.Console.WriteLine($"Location: {queue.Location}"); + System.Console.WriteLine($"IsShared: {queue.IsShared}"); + System.Console.WriteLine($"IsDirect: {queue.IsDirect}"); + System.Console.WriteLine("---"); + } + } + } + } + } +} \ No newline at end of file diff --git a/PrinterDebug.Console/Properties/AssemblyInfo.cs b/PrinterDebug.Console/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..84dcb01 --- /dev/null +++ b/PrinterDebug.Console/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PrinterDebug.Console")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PrinterDebug.Console")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("74AAF6F3-E538-4295-81A0-57634C547B07")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file