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

Posted this the other night just before the big 'meltdown' at fasthosts :mad: hope it wasn't yet another printer script request that did it:o

 

I have two seperate vbs scripts at logon, one to delete networked printers and one to connect to network printers, what I really want but am too dim to do it, is one script that will delete networked printers if they exist and connect/install currently used network printers.

 

 

Nice to be back - well done!

Posted (edited)

could try:

 

On error resume next

 

'Remove's All Network Objects (Printers and Drives)

 

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

Set oDrives = WshNetwork.EnumNetworkDrives

Set oPrinters = WshNetwork.EnumPrinterConnections

For i = 0 to oDrives.Count - 1 Step 2

WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true

Next

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

WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)

 

Next

 

'-----------------------------------------------------------

 

'Map Printers Based On Computer OU Membership

 

Set objSysInfo = CreateObject("ADSystemInfo")

strName = objSysInfo.ComputerName

 

arrComputerName = Split(strName, ",")

arrOU = Split(arrComputerName(1), "=")

strComputerOU = arrOU(1)

 

Set objNetwork = CreateObject("WScript.Network")

 

Select Case strComputerOU

 

'-----------------------------------------------------

 

Case "OU name"

objNetwork.AddWindowsPrinterConnection "\\server\printername"

objNetwork.SetDefaultPrinter "\\server\printername"

 

 

 

Obviously put your OU's and printer share names in and repeat for all printers and OU's

Edited by roty80
spelling
  • Thanks 1

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...