If you ever want to do a prank on a massive scale, you need to find all the printers in your Active Directory, not only ones that are connected to your computer. Oddly enough, the method to find them is not trivial. The code is in c# and it works in Visual Studio 2008.
1: private void FindAllPrinters()
2: {
3: string[] wantedProps = { "name", "servername", "printername",
4: "drivername", "shortservername", "location" };
5:
6: var ds = new DirectorySearcher { Filter = "(objectClass=printqueue)" };
7: foreach (SearchResult sr in ds.FindAll())
8: {
9: Debug.WriteLine(sr.Path);
10: ResultPropertyCollection rpc = sr.Properties;
11:
12: // use rpc.PropertyNames instead of wantedProps if you want to
13: // know more about the printers than is provided below
14: foreach (string property in wantedProps)
15: {
16: foreach (object value in rpc[property])
17: Debug.WriteLine(string.Format("\t{0}: {1}", property, value));
18: }
19: }
20: }
Note that you need to add a reference to System.DirectoryServices. Also keep in mind that this code fetches all the printers in your domain. If you have many domains in your organization, you’ll have to get the list and instantiate DirectorySearcher class separately for each one.
