Solved

vbscript setup printer

Posted on 2014-01-28
2
599 Views
Last Modified: 2014-01-30
I would like to use visual basic script to setup network printers on a remote pc.  this is what i have so far

Dim printer, UNCpath1, slash1, slash2, printername

slash2 = "\\"

slash1 = "\"

printername = InputBox("What printer do you want to be the default? ", "Create Default Printer")

UNCpath1 = InputBox("What server is this printer on? ", "Server")

Set printer = CreateObject("WScript.Network")

printer.AddWindowsPrinterConnection slash2 & UNCpath1 & slash1 & printername

WScript.Quit

It works if I run it on the computer I'm logged into. But I would like to run it on the computer that I am logged into, to install a printer on a remote computer.
Any ideas?
0
Comment
Question by:JeffBeall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39817421
Adding a Printer on a Remote Computer
These two scripts will add an IP port and install a printer on a remote machine. This is good to add a local IP printer on a remote workstation. For this script, you need to install prnadmin.dll. The prnadmin.dll file is available in the Windows Server 2003 Resource Kit Tools.

Add an IP port:
'----------------------------
'http://vbsbob.blogspot.com/
'Required files:prnadmin.dll
'prnadmin.dll is available
'in the Windows Resource Kit located
'at http://www.microsoft.com
'----------------------------


dim oPort
dim oMaster
set oPort = CreateObject("Port.Port.1")
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
Set WshShell = WScript.CreateObject("WScript.Shell")

'Edit for comouter name
strMachineName = "\\computer"

'Edit for IP port name
strPortName = "Name of the Port"

'Edit for IP address
strIPAdress = "Insert Printer IP Address Here"


'Indicate where to add the port. Double quotes ("" ) stand for the local computer, which is the default.
oPort.ServerName = strMachineName

'The name of the port cannot be omitted.
oPort.PortName = strPortName

'The type of the port can be 1 (TCP RAW), 2 (TCP LPR), or 3 (standard local).
oPort.PortType = 1

'Mandatory for TCP ports. This is the address of the device to which the port connects.
oPort.HostAddress = strIPAdress

'For TCP RAW ports. Default is 9100.
oPort.PortNumber = 9100

'Enable or disable SNMP.
oPort.SNMP = false

'Applies to TCP LPR name, default is LPR
oPort.QueueName = "Queue"

'Byte counting or double spool applies to TCP LPR ports, is disabled by default.
oPort.DoubleSpool = false

'Try adding the port.
oMaster.PortAdd oPort
'Test for the status.
If Err <> 0 then

'An error occurred.
WshShell.Popup "Error " & Return & " returned during setup.", 10, "Printer port add.", 16
end if

WshShell.Popup "IP Port Add Successful", 10, "Install Status", 64

Open in new window


Add a Printer on a Remote Computer:

'----------------------------
'http://vbsbob.blogspot.com/
'Required files:prnadmin.dll
'prnadmin.dll is available
'in the Windows Resource Kit located
'at http://www.microsoft.com
'----------------------------

dim oMaster
dim oPrinter
Set WshShell = WScript.CreateObject("WScript.Shell")
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
set oPrinter = CreateObject("Printer.Printer.1")

'Edit for Computer Name
'name of computer you want to add IP port to
strMachineName = "enter computer name here"

'Edit for Printer Name. This is the name users will see when selecting this printer
strPrinterName = "printer display name"

'Edit for Printer Driver Name. This specifies the printer driver to use.
'This must match the print driver name exactly.
'The string is required and cannot be empty.
'Example below is for the HP LaserJet 9040 Post Script
strDriverName = "HP LaserJet 9040 PS"

'Edit for the IP Port Name
'change aaa.bbb.ccc.ddd with the IP address of the printer
strPortName = "IP_aaa.bbb.ccc.ddd"

'Edit for the Driver Path.
'Where you unzipped the printer driver files to.
strDriverPath = "\\computer name\share name\"

'Edit for the INF path. Usually the same as the driver path plus the INF file
'point to where you unzipped the driver files
strINF = "\\computer name\share name\HP LaserJet 9040 PS.inf"


oPrinter.ServerName = strMachineName
oPrinter.PrinterName = strPrinterName
oPrinter.DriverName = strDriverName
oPrinter.PortName = strPortName
oPrinter.DriverPath = strDriverPath
oPrinter.InfFile = strINF

'The following code adds the printer.
oMaster.PrinterAdd oPrinter

'The following code uses the Err object to determine whether the printer was added successfully.
if Err <> 0 then
'An error occurred
WshShell.Popup "Error " & Return & " returned during setup.", 10, "Printer add.", 16
end if

WshShell.Popup "Printer Add Successful", 10, "Install Status", 64

Open in new window


from: http://vbsbob.blogspot.co.il/2008/01/adding-printer-on-remote-computer.html
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 39820700
thank you.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses

626 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