So I have a workaround which seems to do the job well enough after a bit of testing. The printers would have been connected to the machine at somepoint using rundll32 printui.dll,PrintUIEntry /ga /c\\%computername% /n\\%printserver%\%printername%
In the application I've imported printui.dll
:
[DllImport("printui.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern void PrintUIEntryW(IntPtr hwnd, IntPtr hinst, string lpszCmdLine, int nCmdShow);
Then later I use the /ge
flag on the remote machine to list all per-machine connections, output that to a temp text file, then check to see if the printer name is contained in the text file:
PrintUIEntryW(IntPtr.Zero, IntPtr.Zero, "/c \\\\" + compID + " /ge /q /f c:\\temp\\printers.txt", 0);
string file = File.ReadAllText("c:\\temp\\printers.txt");
if (file.Contains(printerID))
{
exist = true;
}
File.Delete("c:\\temp\\printers.txt");
I'm aware this probably isn't the best way to go about it, but it seems to work in the environment I operate in, so I'm providing this as an answer.