Solved Script to check computer and install printer

Microsoft Office professional 2010 softw...
January 30, 2013 at 23:06:48
Specs: Windows 2008, 4G
Hi

Can someone help me put some codes together please, I already have a script which I would like to add a check and install or not install to it.

ComputerName= LCase(WshNetwork.ComputerName)
ShortName = Left(ComputerName, 16)
Select Case ShortName
Case"computer1"
wshnetwork.addwindowsprinterconnection "\\pserver\printer1"
wshnetwork.addwindowsprinterconnection "\\pserver\colourprinter1"
WshNetwork.SetDefaultPrinter "\\pserver\printer1"
Case"computer2"
wshnetwork.addwindowsprinterconnection "\\pserver\printer2"
wshnetwork.addwindowsprinterconnection "\\pserver\colourprinter2"
WshNetwork.SetDefaultPrinter "\\pserver\printer2"
Case"computer3"
wshnetwork.addwindowsprinterconnection "\\pserver\printer3"
wshnetwork.addwindowsprinterconnection "\\pserver\colourprinter3"
WshNetwork.SetDefaultPrinter "\\pserver\printer3"
Case Else
REM WScript.Echo "Problem determining PC location."
End Select


This vbs script is run when a user logins and it will check the computer name and if it matches installed 2 printers and make one of them the default, I want it to check if the computer already have this printer installed and if so don't install it and check the second one and again don't install it if it's installed already and so on checking all the machines.

Thanks


See More: Script to check computer and install printer

Report •

✔ Best Answer
February 6, 2013 at 16:48:22
I think it's solved. This will sometimes popup if we have the same printer installed twice. eg. Printer manager server will install an office printer linking the users GPO and a login script to install the same printer when the users logins to the computer.

I have changed the login script not to include the office printer and so far no errors when the users login.



#1
January 31, 2013 at 18:20:22
I think you want "wshnetwork.enumnetworkprinterconnections". I built it into this untested code, but you can adapt it to your existing chassis once you know how to use it.
'====== begin vbscript
'0:unc of the printer, 1: local assigned name of the printer...
set ptr=wshnetwork.enumprinterconnections
redim a(ptr.count/2)
for i=0 to ptr.count-1 step 2
a(i/2)=ptr(i)
next

pserver="\\pserver"
ComputerName= LCase(WshNetwork.ComputerName)
ShortName = Left(ComputerName, 16)
Select Case ShortName
Case"computer1"
pdeflt="printer1"
pc="colourprinter1"
Case"computer2"
pdeflt="printer2"
pc="colourprinter2"
Case"computer3"
pdeflt="printer3"
pc="colourprinter3"
Case Else
REM WScript.Echo "Problem determining PC location."
End Select
call loadptr(pserver,pdeflt,pc)
wscript.quit

sub loadptr(psrv,p1,p2)
pcheck=filter(a,p1)
if ubound(pcheck)<0 then
wshnetwork.addwindowsprinterconnection psrv+"\"+p1
WshNetwork.SetDefaultPrinter psrv+"\"+p1
end if
pcheck=filter(a,p2)
if ubound(pcheck)<0 then
wshnetwork.addwindowsprinterconnection psrv+"\"+p2
end if
end sub
'====== end vbscript


Report •

#2
January 31, 2013 at 20:53:24
Sorry I don't know really programming, maybe some-one can modify my script since I have about 200 computers to check and about 10 printers on the pserver

Report •

#3
February 2, 2013 at 08:34:40
Question: Why does it matter? If you try to add the printer you already have, AddWindowsPrinterConnection returns without doing anything, so you don't have to check. Just add the printer, and either way you'll have it installed at the end of the function.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
February 3, 2013 at 16:52:53
I thought it might cause problems if it gets installed twice or it might slow down the login since it is repeating the install.
I am trying to isolate the problem since I am getting this script error "The environment is incorrect code:8007000A source (null). The script works once it is logged in and executed manually but sometimes it gives me this error when a user logins in the login script.
We have a printer server which installs 1 printer using the print manager and GPO and then a script which runs when the users logins and some machines will get the same printer installed twice so I am seeing if this has anything to do with it.

Report •

#5
Report •

#6
February 4, 2013 at 16:24:00
Not sure how you found that link since I google that error and couldn't find anything.
I have read it and GPO result do have "Always wait for the network at computer startup and logon" enabled, so that's not the problem.
I have created another vbs script without the printers being loaded again on that batch of computers and it seem it's not popping up anymore, will monitor it for a few days.

Report •

#7
Report •

#8
February 4, 2013 at 19:16:18
Tried it again:
"The environment is incorrect code:8007000A source (null) in google.com
Got some sites but nothing related to this issue or could find your search.
Maybe it's the region?

Report •

#9
February 5, 2013 at 06:07:03
I don't know; I just went with the error number.

Actually, why aren't you running this script on the computer's startup? Unless there's an actual reason, system configuration should be done with the system's configuration scripts. Or alternatively, just put in a 15 second sleep at the start of the script.

How To Ask Questions The Smart Way


Report •

#10
February 5, 2013 at 21:55:29
I try running a printer install script using computer startup GPO but it doesn't install anything, I added domain computer to it etc.

Anyway I am using the user configuration so when users login it will run the script, check what computer they are on and install it. While the print manager will install the printer to the a GPO that is linked to the OU.


Report •

#11
February 6, 2013 at 16:48:22
✔ Best Answer
I think it's solved. This will sometimes popup if we have the same printer installed twice. eg. Printer manager server will install an office printer linking the users GPO and a login script to install the same printer when the users logins to the computer.

I have changed the login script not to include the office printer and so far no errors when the users login.


Report •

Ask Question