SCRIPT: Share and unshare printers automatically

Share local printers:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = FALSE")

i = 1

For Each objPrinter in colInstalledPrinters
objPrinter.Shared = TRUE
objPrinter.ShareName = objPrinter.Name
objPrinter.Put_
i = i + 1
Next

Unshare local printers:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = FALSE")

i = 1

For Each objPrinter in colInstalledPrinters
objPrinter.Shared = FALSE
objPrinter.ShareName = objPrinter.Name
objPrinter.Put_
i = i + 1
Next

Advertisements

Posted on 07/10/2009, in Scripting. Bookmark the permalink. Leave a comment.

Comments are closed.

%d bloggers like this: