Set Default Printer

Option Explicit

Dim objShell,grouplistD,ADSPath,userPath,listGroup

Dim WshNetwork

On Error Resume Next

set objShell = WScript.CreateObject( "WScript.Shell" )

Set WshNetwork = CreateObject("WScript.Network")   

 

If isMember("PrinterA") Then

       WshNetwork.SetDefaultPrinter "\\research\libraryA"

      

End If

If isMember("PrinterB") Then

       WshNetwork.SetDefaultPrinter "\\research\libraryB"

      

End If

 

Function IsMember(groupName)

    If IsEmpty(groupListD) then

        Set groupListD = CreateObject("Scripting.Dictionary")

        groupListD.CompareMode = 1

        ADSPath = EnvString("userdomain") & "/" & EnvString("username")

        Set userPath = GetObject("WinNT://" & ADSPath & ",user")

        For Each listGroup in userPath.Groups

            groupListD.Add listGroup.Name, "-"

        Next

    End if

    IsMember = CBool(groupListD.Exists(groupName))

End Function

 

Function EnvString(variable)

    variable = "%" & variable & "%"

    EnvString = objShell.ExpandEnvironmentStrings(variable)

End Function

Set objShell = Nothing