Script to Connect Network Printers on non-domain computers.

Hey everybody!

Here's the situation. I have a couple of multipurpose printer/fax/scanners on the network. Everyone that brings in their laptop needs to be able to use those printers, but nobody has domain accounts to log in and share the printer from the server.

Up to now, we us a script to map a drive to the server, run a vb script to install the printers and then disconnect the drive. However, now there are users who have vista and windows 7 x64, and the printer intall does not work.

Attached is the install script. Can someone help me modify this to work with Vista and Windows 7 x64? This is just for one printer, I have another script for the other printer. I would like to have them both installed with one script, but can't figure that part out either.

Thanks in advance for the help!
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "regsvr32 /s \\server\shared\Departments\IT\drivers\PrinterDLL\prnadmin.dll", 1, true
Set oShell = Nothing

Dim oPrinter
Dim oMaster

Set WshNetwork = WScript.CreateObject("WScript.Network")

'gets computer name
strComputer = WshNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

'before adding printer we need to create ports that printers will use
objNewPort.Name = "IP_192.168.111.85:print"
objNewPort.Protocol = 2
objNewPort.HostAddress = "192.168.111.85"
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

set oPrinter = CreateObject("Printer.Printer.1") 
set oMaster = CreateObject("PrintMaster.PrintMaster.1") 

oPrinter.PrinterName = "RICOH Aficio MP C6000 PCL 5c" ' name of printer how it's appear at printer' s directory
oPrinter.DriverPath = "\\server\Shared\Departments\IT\Drivers\Ricoh_6000" 'if there is special driver to install you must indicate a path
oPrinter.InfFile = "\\server\Shared\Departments\IT\Drivers\Ricoh_6000\OEMSETUP.inf"
oPrinter.DriverName = "RICOH Aficio MP C6000 PCL 5c" ' name of printer whow it's apear in ntprint.inf
oPrinter.PortName = "IP_192.168.111.85:print" ' name of port that you created before
oMaster.PrinterAdd oPrinter


If Err <> 0 then
msgbox "Error on installation of printers."
end if

msgbox "Your printer is now installed and ready to use."

Open in new window

NursingCorpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jostranderCommented:
Is it just the drivers that are incompatible?

You could have the script determine whether it's 64/32 bit and select which folder.

This script assumes a new folder for 64bit drivers.  I have not tested it...
ON ERROR RESUME NEXT

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "regsvr32 /s \\server\shared\Departments\IT\drivers\PrinterDLL\prnadmin.dll", 1, true

Dim oPrinter
Dim oMaster
Dim strDriverPath
Dim strDriverPath64
strDriverPath = "\\server\Shared\Departments\IT\Drivers\Ricoh_6000"
strDriverPath64 = "\\server\Shared\Departments\IT\Drivers\Ricoh_6000_64"

Set colEnvSystem = oShell.Environment("System")
WindowsProcessorArchitecture = colEnvSystem("PROCESSOR_ARCHITECTURE")

'If not 32bit, set path to 64bit files
If WindowsProcessorArchitecture<>"x86" then
	strDriverPath = strDriverPath64
End IF

Set WshNetwork = WScript.CreateObject("WScript.Network")

'gets computer name
strComputer = WshNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

'before adding printer we need to create ports that printers will use
objNewPort.Name = "IP_192.168.111.85:print"
objNewPort.Protocol = 2
objNewPort.HostAddress = "192.168.111.85"
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

set oPrinter = CreateObject("Printer.Printer.1") 
set oMaster = CreateObject("PrintMaster.PrintMaster.1") 

oPrinter.PrinterName = "RICOH Aficio MP C6000 PCL 5c" ' name of printer how it's appear at printer' s directory
oPrinter.DriverPath = strDriverPath 'if there is special driver to install you must indicate a path
oPrinter.InfFile = strDriverPath & "\OEMSETUP.inf"
oPrinter.DriverName = "RICOH Aficio MP C6000 PCL 5c" ' name of printer whow it's apear in ntprint.inf
oPrinter.PortName = "IP_192.168.111.85:print" ' name of port that you created before
oMaster.PrinterAdd oPrinter


If Err <> 0 then
msgbox "Error on installation of printers."
end if

msgbox "Your printer is now installed and ready to use."

Open in new window

0
NursingCorpAuthor Commented:
Thank you for the reply. This works fine on the 32bit systems, and when I get to a 64bit, it says that activex could not create the object "Printer.Printer.1".
0
NursingCorpAuthor Commented:
The drivers are valid and exist, I just put them there from the Ricoh website.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

jostranderCommented:
I think the issue may be with the PrinterAdmin tool (prnadmin.dll).  Maybe it is incompatible with the 64 bit OS.

Here is a new script that does the adding of the driver without using the PrinterAdmin DLL.  

I could only test on 32bit Win7 and XP, so please let me know how it works for you.
ON ERROR RESUME NEXT

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")

Dim strDriverPath
Dim strDriverPath64
strDriverPath = "\\server\Shared\Departments\IT\Drivers\Ricoh_6000"
strDriverPath64 = "\\server\Shared\Departments\IT\Drivers\Ricoh_6000_64"
strDriverName="RICOH Aficio MP C6000 PCL 5c"
strPortName = "IP_192.168.111.85:print"
strHostname = "192.168.111.85"
strPortNum = "9100"

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate"  & _
	",(loaddriver)}!\\.\root\cimv2")
	
	
'If not 32bit, set path to 64bit files
Set colEnvSystem = oShell.Environment("System")
WindowsProcessorArchitecture = colEnvSystem("PROCESSOR_ARCHITECTURE")
If WindowsProcessorArchitecture<>"x86" then
        strDriverPath = strDriverPath64
End IF


'=======================================================
'	Create the ports
'=======================================================
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = strPortName
objNewPort.Protocol = 2
objNewPort.HostAddress = strHostname
objNewPort.PortNumber = strPortNum
objNewPort.SNMPEnabled = False
objNewPort.Put_

If err.number <> 0 then
	msgbox "There was an error creating the Printer Port.",vbExclamation,"Printer Port Install"
	wscript.quit
End If

'=======================================================
'	Add the Driver
'=======================================================
Set NewDriver = objWMIService.Get("Win32_PrinterDriver")
NewDriver.InfName = strDriverPath & "\OEMSETUP.inf"
NewDriver.Name = strDriverName
Result = NewDriver.AddPrinterDriver(NewDriver)

If Result <> 0 then
	msgbox "There was an error adding the printer driver.",vbExclamation,"Printer Driver Install"
	wscript.quit
End If

'=======================================================
'	Add the printer.
'=======================================================
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = strDriverName
objPrinter.PortName   = strPortName
objPrinter.DeviceID   = strDriverName
objPrinter.Location = ""
objPrinter.Network = False
objPrinter.Shared = False
objPrinter.Put_

If Err.number <> 0 then
	msgbox "Error on installation of printer.",vbExclamation,"Printer Install"
Else
	msgbox "Printer:  " & strDriverName & vbCrLf & vbCrLf & _
		"Is now installed and ready to use.",vbInformation,"Printer Install"
end if

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jostranderCommented:
I left the part in there to check 64 vs. 32 bit... not sure if the drivers work on both or not.  Ricoh had separate ones for 64 & 32 on the website.

Thanks,
Joe
0
NursingCorpAuthor Commented:
Right On!!! You rock, that did the trick perfectly!

Thank you so much!
0
NursingCorpAuthor Commented:
Best response ever, thanks!
0
jostranderCommented:
woohoo!  Glad I could help... and learned some stuff in the process.

Thanks,
Joe
0
NursingCorpAuthor Commented:
Yeah, they have different divers based on the os, that was the problem, so this is checking to see what version, and then selecting the right version for install, I love it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.