[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

vb script to connect network printer

Posted on 2006-05-28
14
Medium Priority
?
1,099 Views
Last Modified: 2012-06-21
We share office space with another tennant who needs to access our Network printers. They are on a workgroup, we are on a domain. I've installed another NIC in our print server (Win 2003Std) and assigned in an IP address within their segment. I can browse to the print server and need to enter domain usernam and password. After doing this I can connect each of the workstations to our printers and print OK. After rebooting the workstations I can no longer print and get the message "Print spooler not running" (even thought it is.). I need to then delete and re-add each printer.

One idea I had was to ass the printer each time usig the below vbs script, but how do I pass domain user credential in the script so user is not prompted?

('// Name: setprint.vbs
'// Description: Add a network printer and make it the default

Set WshNetwork = CreateObject("WScript.Network")

'// Adds the printer. Substitute your server name and printer share.
WshNetwork.AddwindowsPrinterConnection "\\servername\sharename"

'// Makes the specified printer the default.
WshNetwork.SetDefaultPrinter "\\servername\sharename"

Many Thanks.
0
Comment
Question by:screamsavers
11 Comments
 
LVL 6

Expert Comment

by:Dark_King
ID: 16783186
Not what you ask for but you can use “net” to map a printer.

net use lpt2 \\ComputerName\ShareName password /USER:username

Or you can execute this net command from inside VB code.
0
 

Author Comment

by:screamsavers
ID: 16783862
Thanks DK, however I believe that doing it this way using 'net use' does not add the printer in printers and faxes, and I would like to have this happen.

0
 
LVL 2

Expert Comment

by:Klintan
ID: 16784040
Use the AddPrinterConnection method instead.

quick refrence
object.AddPrinterConnection(strLocalName, strRemoteName[,bUpdateProfile][,strUser][,strPassword])

so change the line
WshNetwork.AddwindowsPrinterConnection "\\servername\sharename"
with
WshNetwork.AddPrinterConnection "LPT1", "\\servername\sharename", false, "Username", "Password"


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:Lazarus
ID: 16784121
The below will add a SHARED printer on your Server or WORK station to whom ever runs it.
You can also set the printer as a defualt or not by removing the " ' " from the last line
Change the PrinterDrive Name and Printer Share name accordingly as well.

Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\SERVERNAME\iR5000"
PrinterDriver = "Canon iR5000-6000 PS3"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
'WshNetwork.SetDefaultPrinter "\\SERVERNAME\iR5000"
0
 
LVL 2

Expert Comment

by:Klintan
ID: 16784225
You could also initate with username and password before you add your printer connection

Dim WshShell
set WshShell = CreateObject("wscript.Shell")
WshShell.Run "cmd /c net use \\servername\ipc$ /user:username password" 'servername=printserver

0
 
LVL 20

Expert Comment

by:Lazarus
ID: 16785690
There is no need to intiate username or password if you have your printer setup without restrictions on shared computer, or as long as your normal user has the proper rights given to him in the AD
Why would want to display in a script a username or password anyhow? The only reason you might need to use it that way is if you are not using Active Directory.
0
 
LVL 2

Accepted Solution

by:
Klintan earned 252 total points
ID: 16786015
Well that is the problem. It's both AD and workgroup.
0
 
LVL 20

Assisted Solution

by:Lazarus
Lazarus earned 248 total points
ID: 16786755
Well that problem can be fixed by encrypting the VBS file.
There are more than a few ways to skin that cat.  But leaving a Username and Password in an exposed script is not smart at all. Not if you want a secure Network anyways.
Here's one such solution: http://www.experts-exchange.com/Web/Web_Languages/Q_20531269.html?query=vb+script+encrypt&clearTAFilter=true

I would recommend however that you ad your workgroup into your AD however so that they are part of your Network's AD. If you need to restict them for some other reason from your network, Use Groups and GPO to do that , and or also use a seperate Subnet to help out as well.
0
 
LVL 2

Expert Comment

by:Klintan
ID: 16787748
The author of this question wanted to pass user credentials in the script. Your idea is great but I do not see how the link yould help the user.
0
 
LVL 20

Expert Comment

by:Lazarus
ID: 16789721
It's just a workaround to keep USERNAME/PASSWORD from being broadcast. It would be alot easier to just roll everything into the AD though, since the credentials are passed without the script, like I said. But it's all still workable.
0
 
LVL 2

Expert Comment

by:Klintan
ID: 17213711
That works for me.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us in IT utilize a combination of roaming profiles and folder redirection to ensure user information carries over from one workstation to another; in my environment, it was to enable virtualization without needing a separate desktop for each…
Resolve DNS query failed errors for Exchange
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question