{"id":20526544,"url":"https://github.com/nikvoronin/howdy-mr-printer","last_synced_at":"2026-05-06T18:36:02.581Z","repository":{"id":144197566,"uuid":"454910887","full_name":"nikvoronin/howdy-mr-printer","owner":"nikvoronin","description":"How to check the printer status in Windows","archived":false,"fork":false,"pushed_at":"2022-02-02T20:45:06.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T11:27:05.165Z","etag":null,"topics":["cim","csharp","dotnet","printer","printer-errors","printer-monitor","printer-status","printers","windows","wmi"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikvoronin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-02-02T19:40:35.000Z","updated_at":"2023-11-27T06:53:21.000Z","dependencies_parsed_at":"2023-06-16T07:30:25.003Z","dependency_job_id":null,"html_url":"https://github.com/nikvoronin/howdy-mr-printer","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"259ad7b29243d740429c3368565dcf81a18d9879"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2Fhowdy-mr-printer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2Fhowdy-mr-printer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2Fhowdy-mr-printer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikvoronin%2Fhowdy-mr-printer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikvoronin","download_url":"https://codeload.github.com/nikvoronin/howdy-mr-printer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242133430,"owners_count":20077095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cim","csharp","dotnet","printer","printer-errors","printer-monitor","printer-status","printers","windows","wmi"],"created_at":"2024-11-15T23:14:39.042Z","updated_at":"2026-05-06T18:36:02.572Z","avatar_url":"https://github.com/nikvoronin.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Howdy Mr Printer\n\nThis is a small console app that monitors a Windows printer's health using WMI (Win32_Printer) and prints current status.\n\n```log\nMonitoring: Microsoft Print to PDF\nReady | State:Idle | Status:Idle | DetectedError:Unknown | DetectedErrorEx:Unknown\nReady | State:Idle | Status:Idle | DetectedError:Unknown | DetectedErrorEx:Unknown\n...\nReady | State:17408 | Status:Printing | DetectedError:NoError | DetectedErrorEx:Unknown\nReady | State:Unk_Printing | Status:Printing | DetectedError:NoError | DetectedErrorEx:Unknown\nReady | State:Idle | Status:Idle | DetectedError:Unknown | DetectedErrorEx:Unknown\nReady | State:Idle | Status:Idle | DetectedError:Unknown | DetectedErrorEx:Unknown\n...\nReady | State:Idle | Status:Idle | DetectedError:Unknown | DetectedErrorEx:Unknown\n```\n\n- Determines which printer to monitor (from command line or a default name).\n- Every second:\n    - Queries WMI for that printer.\n    - Reads its state, status, and error flags.\n    - Decides if the printer is `OK` or `FAULTY`.\n    - Logs the result.\n    - Await `Task.Delay(1000)` pauses for ~1 second between checks.\n- Stops when you press a key.\n\nTo access WMI (Windows Management Instrumentation) the project `using System.Management` namespace methods. The program uses top-level statements (no explicit Main method).\n\n## Build and Run\n\nBuild and run on Windows with .NET, for example:\n\n```shell\ndotnet run \"My Printer Name\"\n```\n\nor just:\n\n```shell\ndotnet run\n```\n\nIf you don't specify a printer name in the arguments, it defaults to watching `Microsoft Print to PDF`. Find it in the following lines:\n\n```csharp\nconst string DefaultPrinterName = \"Microsoft Print to PDF\";\n```\n\n## Querying WMI\n\n`DoHealthCheck(string nick)` is where it talks to Windows:\n\nIt builds a WMI query for the printer:\n\n```csharp\nstring query = $\"SELECT * from Win32_Printer WHERE Name LIKE '%{nick}%'\";\n```\n\nUses ManagementObjectSearcher:\n\n```csharp\nusing ManagementObjectSearcher searcher = new(query);\nusing ManagementObjectCollection folks = searcher.Get();\n```\n\nThen iterates over the printers returned:\n\n- For each `buddy` in `folks`, it reads the printer's `DeviceId` via the extension method `ValueOrDefaultOf`.\n- If `DeviceId` contains the nickname (`nick`), that's considered the matching printer.\n- For that one, it calls `AreYouReady( buddy)` to decide if it is OK or in fault.\n\nAfter the loop, it calls:\n\n```csharp\nGC.Collect();\nGC.WaitForFullGCComplete(\n    TimeSpan.FromMilliseconds(100));\n```\n\nwhich forces garbage collection and waits for a full GC. This is a bit aggressive, presumably to quickly free unmanaged resources related to WMI objects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikvoronin%2Fhowdy-mr-printer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikvoronin%2Fhowdy-mr-printer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikvoronin%2Fhowdy-mr-printer/lists"}