Solved

Scripting the addition of  network prnter

Posted on 2006-07-17
24
313 Views
Last Modified: 2008-02-01
Looking for an easy script to add a network printer. I've tried a few but keep getting "permission denied" in a vbs window. Lookslike I need a username and password somewhere when it adds the printer.
0
Comment
Question by:prlit
  • 14
  • 5
  • 3
  • +2
24 Comments
 
LVL 13

Expert Comment

by:haim96
Comment Utility
if you don't have permission to add the printer it's mean that you need
to supply user + pass within the script (probably admin's )
and i'm not sure you want to do that ...
any way, is this  network printer connected with network card
or it's shared on via network computer ?
if it's connected with network card you need to be admin
because it require driver installation.
if it's only shared (and security is defualt) most of the time you don't need to be admin ....
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
No, it's shared from another PC and I'd like to supply the login info within the script.

Thanks
0
 
LVL 3

Expert Comment

by:danishtahir
Comment Utility
Can you post your script?
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
Copy & paste the following into a text editor and save with a .vbs extension.

'// 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 "\\Server\printer"

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

Also:


'
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\alan\Epson."



Also tried:
' Guy Thomas February 2004.
' ******************************
Option Explicit
Dim netPrinter, UNCpath
UNCpath = "\\YourServer\PrinterName"
Set netPrinter = CreateObject("WScript.Network")
netPrinter.AddWindowsPrinterConnection UNCpath
WScript.Echo "Your printer is mapped from : " & UNCpath
WScript.Quit
' End of example VBScript


Always get permission denied.
0
 
LVL 3

Expert Comment

by:danishtahir
Comment Utility
If you click on start, then in run type

\\alan\Epson

what happens?
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
it prompts me for a user/pass
0
 
LVL 3

Expert Comment

by:danishtahir
Comment Utility
so, it means that you will need to configure a username/password you have on the host machine identical to the one where you are connecting from. This should solve your problem.
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
but there's no way to include it in the script? We're talking over 150 Pc's
0
 
LVL 13

Expert Comment

by:haim96
Comment Utility
it's a domain network ? or workgroup ?
0
 
LVL 13

Expert Comment

by:haim96
Comment Utility
any way , try to combine the add printer from command line from here :
http://www.windowsitpro.com/Article/ArticleID/14539/14539.html?Ad=1

with the "runas" command. ( type "runas /?" int cmd window to get full syntex )
this should alow you to add network printer with alternative credentials
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
it's a workgroup.
0
 
LVL 13

Expert Comment

by:haim96
Comment Utility
try this:
c:\runas /user:server\admin "rundll32 printui.dll,PrintUIEntry  /in /n\server\printer" <pass.txt

when:
server= the computer with the printer
admin = your admin user
printer = printer name
pass.txt = text file that contain the admin password


0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:prlit
Comment Utility
so: c:\runas /administrator:192.168.1.67\admin "rundll32 printui.dll,PrintUIEntry  /in /n\192.168.1.67\WinPrint1" <pass.txt
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
system cannot find the file specified.
0
 
LVL 13

Accepted Solution

by:
haim96 earned 500 total points
Comment Utility
because you need to create it  :)
create file named pass.txt with your password (no extra lines,spaces etc) and save it in c:\
and it's :
c:\runas /user:192.168.1.67\administrator "rundll32 printui.dll,PrintUIEntry  /in /n\192.168.1.67\WinPrint1" <pass.txt
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
'C:\runas' is not recognized as an internal or external command, operable program or batch file.
0
 

Expert Comment

by:bgssgk
Comment Utility
what operating system is the client machine, the runas command may not be available
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
Windows XP Pro SP2
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
It's there - if I type runas - I get all of the info for the cmd.
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
I know what I did wrong. I got it go go farther

runas /user:PRINTSERVER2\administrator "rundll32 printui.dll,PrintUIEntry  /in /n\192.168.1.67\WinPrint1" <pass.txt

enter the password for PRINTSERVER2\administrator:

then it says attempting to start rundll32 printui.dll,PrintUIEntry  /in /n\192.168.1.67\WinPrint1" as user PRINTSERVER2\administrator

then I get a logon failure. My pass.txt file just has the password in it - nothing else.
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
Is one of those usernames from my printing host or both?
0
 
LVL 1

Expert Comment

by:JexPam
Comment Utility
My best advice- Get a network card (can be an external adapter such as the HP Jetdirect 170x Print Server) for the printer and then install the printer local on every workstation pointing to its IP address.
This is a preventative step to the countless “I cant print” support requests because the host workstation is turned off.

As for the current host workstation – make sure File and print sharing is enables and enabled in the firewall.
Go into control panel > User accounts; and create a user for the share access. Something like “printer / printer” and grant it whatever permission level you want (in the local groups).

Also make sure the user on the workstation you are trying to install the printer on has greater than “User” permission for the install to be successful.
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
We're talking 9 printers as well. That would get expensive. I just need a quick and easy way to share them to a PC.
0
 
LVL 1

Author Comment

by:prlit
Comment Utility
That worked.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
Just about everyone has an old PC laying around.  Ask anyone in the IT industry, whether they are a professional or play in it as a hobby.  From outdated Desktops to cheap "throwaway" laptops, they are all around and not as hard to "fix up" as you m…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now