Code:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2\")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_UserAccount Where LocalAccount = False") 'Searches all non-local clients
For Each objItem in colItems
If objItem.Domain <> "printdeny" Then
Dim objNetwork 'Declaration of the network
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\oaktonhs03\library1", True, True
objNetwork.AddWindowsPrinterConnection "\\oaktonhs03\library1"
Dim objPrinter 'Declaration of new variable
Set objPrinter = CreateObject("WScript.Network") 'Makes Object of current network
objPrinter.SetDefaultPrinter "\\oaktonhs03\library1"
WScript.Echo("Success!")
End if
If objItem.Domain = "printdeny" then
WScript.Echo("You do not have permissions!")
End if
Next
WScript.Quit
My purpose here is to check if the current domain account logged in to the computer is part of the group "printdeny" and if it is, then it shows a message that the user does not have permissions. Any user that is not prat of that group will have G.Thomas's script run and display success.
I don't understand a few parts of this script, although I wrote it, it was mainly based on research and not pure knowledge.
First off, I could not figure out why people online made the strComputer = "."
Is the dot a wildcard or what?
Also, is the script up there correct to connect to the network and check the domain of the user?
At the moment, I am getting both of the messages come up, Success and No Permissions on any computer, no matter what.
PLEASE HELP!!