Code Snippet
On error Resume Next
Err.clear 0
Set objUser = WScript.CreateObject("WScript.Network")
wuser=objUser.UserName
If Time <= "12:00:00" Then
MsgBox ("Bom Dia "+Wuser+", SUA IMPRESSORA FOI ALTERADA....TENHA CALMA USUARIO!")
ElseIf Time >= "12:00:01" And Time <= "18:00:00" Then
MsgBox ("Boa Tarde "+Wuser+", SUA IMPRESSORA FOI ALTERADA....TENHA CALMA USUARIO!")
Else
MsgBox ("Boa Noite "+wuser+", SUA IMPRESSORA FOI ALTERADA....TENHA CALMA USUARIO!")
End If
Const NETWORK = 22
Set objNetwork = CreateObject("WScript.Network")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
For Each objPrinter in colPrinters
If objPrinter.Attributes And NETWORK Then
strPrinter = objPrinter.Name
objNetwork.RemovePrinterConnection strPrinter
End If
Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case strGroupName
Case "Administrativo"
objNetwork.AddWindowsPrinterConnection "\\W2K3PRT01\HP4345-Controladoria"
objNetwork.SetDefaultPrinter "\\W2K3PRT01\HP4345-Controladoria"
objNetwork.AddWindowsPrinterConnection "\\W2K3PRT01\HP4345-Mezanino"
objNetwork.AddWindowsPrinterConnection "\\W2K3PRT01\HP4345-Mezanino"
Case "TI"
objNetwork.AddWindowsPrinterConnection "\\W2K3PRT01\HP4345-CPD"
objNetwork.SetDefaultPrinter "\\W2K3PRT01\HP4345-CPD"
objNetwork.AddWindowsPrinterConnection "\\W2K3PRT01\HP4345-Mezanino"
objNetwork.AddWindowsPrinterConnection "\\W2K3PRT01\HP3505-Presidencia"
End Select
Next
Wscript.Quit