Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Any help would be recieved with open arms!!!!

Just put the following logon script to map a printer in a OU GPO that I have been using to test policys before deploying them to a new domain, it worked fine with test user account but when I added another user to the OU nothing!!!!

 

Set objNetwork = CreateObject("WScript.Network")

objNetwork.AddWindowsPrinterConnection "\\europa\itlaser"

objNetwork.SetDefaultPrinter "\\europa\itlaser"

 

any ideas, PLEASE.

Posted

This is the printer script I use, adds the printer depending on the OU the computer in, rather than the user. Works great in here, add printer to server, add it to script, job done, it'll add itself to any computers in that department from then on.

 

Created with help from EDUGeek chaps:

 

 

on error resume next

'Set variables.

 

Set shell= WScript.CreateObject("WScript.Shell")

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

dim Counter, PrinterPath

Set objWshNetwork = CreateObject("WScript.Network")

Set objAdsSystemInfo = CreateObject("adsysteminfo")

Set objComputerName = GetObject("LDAP://" & objAdsSystemInfo.ComputerName)

Set objOU = GetObject(objComputerName.Parent)

strOU = replace(objOU.Name,"OU=","")

Set oPrinters = WshNetwork.EnumPrinterConnections

 

Dim computerName

computerName = LCase(WshNetwork.ComputerName)

 

'Add printers depending on AD OU containing computer.

 

Select Case strOU

Case "IT1"

removePrinters

addPrinter "\\print\Dell1700 IT1",True

addPrinter "\\print\HP2500C IT1",False

Case "IT2"

' removePrinters

addPrinter "\\print\HP LJ P2015n IT2",True

 

end select

 

function removePrinters()

 

FOR Counter = 0 to oPrinters.Count - 1

IF mid(oPrinters.Item(Counter), 1, 2) = "\\" THEN

PrinterPath = oPrinters.Item(Counter)

WshNetwork.RemovePrinterConnection PrinterPath, True, True

end if

next

 

end function

 

function addPrinter(strConnectString,isDefault)

 

if strConnectString <> "" then

strResult = WshNetwork.AddWindowsPrinterConnection(strConnectString)

if isDefault then

WshNetwork.SetDefaultPrinter strConnectString

end if

end if

end function

 

 

============

 

The true/false statements after the printer name dictate whether it's set as default or not. "removeprinters" only removes network and not local printers.

Posted

Here is an example of a script we use for the LRC.

Note: The word school refers to the name of your server you use at your place.

 

rem ** Next line must not be deleted **

Set WshNetwork = CreateObject("WScript.Network")

 

rem ** This will delete existing printers **

On Error Resume Next

Set oPrinters = WshNetwork.EnumPrinterConnections

For i = 1 to oPrinters.Count - 1 Step 2

WshNetwork.RemovePrinterConnection oPrinters.Item(i)

Next

 

rem ** Setup new printer connection **

WshNetwork.AddWindowsPrinterConnection "\\SchoolPrint.School.local\LRC"

 

rem ** Setup default printer **

WshNetwork.SetDefaultPrinter "\\SchoolPrint.School.local\LRC"

MsgBox "Added Printer: LRC. This printer is default"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...