• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Mapping printers in VB.net

Smoblikat

Diamond Member
Hello, I am trying to write a program that will allow users to select a printer from a listbox and have it automatically add it to their machine. I think im on the right track with the code, but I keep running into a strange issue:

Code:
   Shell("rundll32 printui.dll,PrintUIEntry /in /n\\<PrintServerName>\MS - Library")

The problem that im having is that for some reason, windows is trying to connect to MS, instead of MS - Library. I read here:
http://www.vbforums.com/showthread....Network-Printer-to-All-Profiles-on-a-Computer

That if your networked printer name contains spaces, then to put double quotes around it, but I tried every single quote combination possible and it didnt help. I also created a string with the name of the printer and tried using that, but no matter what it cant figure out how to read past the MS part. Any help would be appreciated.
 
Code:
Shell("rundll32 printui.dll,PrintUIEntry /in /n""\\<PrintServerName>\MS - Library""")

See if that works.
 
Code:
Shell("rundll32 printui.dll,PrintUIEntry /in /n""\\<PrintServerName>\MS - Library""")
See if that works.

That worked perfectly! Thank you very much for the help. Heck, you can even take the rest of the day off, youve earned it 🙂
 
OK then, so now I guess I have a new problem 😛

I am trying to set the newly mapped printer as default, but I cant get it to do that either. I read on technet that the switch I want is /y, but even after reading all the examples I cant get it to set the printer as default. My current code looks like:
Code:
Shell("rundll32 printui.dll,PrintUIEntry /y /in /n""\\<print_server>\MS - Library""")
I have put the /y after the /in too, and that just results in the name being wrong again.
 
So I found a workaround, but its not really user friendly:
Code:
                Shell("rundll32 printui.dll,PrintUIEntry /in /n""\\<Print Server>\MS - Library""")
                MessageBox.Show("Please wait for installation to complete, then press enter")
                Shell("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n""\\<print server>\MS - Library""")

Basically all this does is add the printer, popup a messagebox before the computer tries to set it as default, then sets it as default once you hit OK. Im still hoping there is a way to do this without any user intervention or wait timers.
 
Looks like shell has a wait option. Maybe that would help?

Great idea, thats exactly what I was looking for. My current code looks like this:
Code:
                Shell("rundll32 printui.dll,PrintUIEntry /in /n""\\<print server>\MS - Library""", ,True)
                Shell("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n""\\<print server>\MS - Library""")
It adds the printer, waits for that operation to complete, then moves onto the next line of code which sets it as default.

Thank you!
 
Thread should be titled "mapping printer from command line". It is not really relevant to VB.
 
Back
Top