Get printers from remote machine and add to listBox1
hi all,
i want add network printers on remote machine listbox. googling found couple of visual basic scripts meant visual studio reporting set , no longer used.
right have scheduled task runs every morning outputs list of shared printers on server text file c sharp app reads more automated , read directly server's printer list.
can advise me need this, or learn how populate this?
notes:
code found online:
strcomputer = ".";
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2");
set colitems = objwmiservice.execquery("select * win32_printer",, 48);
for each objitem in colitems;
(change . server name). put in each code listbox1.items.add;
my current code:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.management; using system.diagnostics; namespace getlcprintprinters { public partial class form1 : form { public form1() { initializecomponent(); listbox1.sorted = true; string[] lines = system.io.file.readalllines("t:\\pwm\\printers.txt"); listbox1.items.addrange(lines); (int n = listbox1.items.count - 1; n >= 0; --n) { string removelistitem = "sharename"; if (listbox1.items[n].tostring().contains(removelistitem)) { listbox1.items.removeat(n); } } } public void button1_click(object sender, eventargs e) { string printerwanted; printerwanted = listbox1.selecteditem.tostring().trim(); string script; //script = "rundll32 printui.dll,printuientry /in /n" + printerwanted; string quote = "\""; script = " printui.dll,printuientry /in /n" + quote + "\\\\lcprint\\" + printerwanted + quote; process proc = new process(); proc.startinfo.filename = "rundll32"; proc.startinfo.arguments = script.tostring(); proc.startinfo.createnowindow = false; proc.startinfo.useshellexecute = true; proc.start(); } public void listbox1_selectedindexchanged(object sender, eventargs e) { string printerwanted; string quote = "\""; printerwanted = listbox1.selecteditem.tostring().trim(); textbox1.text = quote + "\\\\lcprint\\" + printerwanted + quote; } } }
thank help,
chmmr.
hi chmmr,
thank posting here.
for question, download source file form how hardware information (cpu id, mainboard info, hard disk serial, system information , ...) in code project.
i tried it. works well.
i hope helpful.
best regards,
wendy
msdn community support
please remember click "mark answer" responses resolved issue, , click "unmark answer" if not. can beneficial other community members reading thread. if have compliments or complaints msdn support, feel free contact msdnfsf@microsoft.com.
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment