Skip to content

Commit

Permalink
Add Printer Debug Console App
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrit-amagno committed Aug 27, 2024
1 parent 700446f commit 80f025b
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
57 changes: 57 additions & 0 deletions PrinterDebug.Console/PrinterDebug.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{74AAF6F3-E538-4295-81A0-57634C547B07}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PrinterDebug.Console</RootNamespace>
<AssemblyName>PrinterDebug.Console</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Data"/>
<Reference Include="System.Drawing" />
<Reference Include="System.Printing" />
<Reference Include="System.Xml"/>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
87 changes: 87 additions & 0 deletions PrinterDebug.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -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("---");
}
}
}
}
}
}
35 changes: 35 additions & 0 deletions PrinterDebug.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]

0 comments on commit 80f025b

Please sign in to comment.