VBScript for AD – Working, but not as intended

Home Forums Scripting General Scripting VBScript for AD – Working, but not as intended

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    Spiritnblk
    Member
    #128174

    I put this script togather with help from previous threads. I have a few printers that are secure, and I wanted to create a script to allow only those with permissions in AD to connect to it. It works, but if there multiple groups for the user it causes them to run through a series of rejections before it connects. Any ideas?

    Dim objDomain, DomainString, UserName, UserObj, strComputer

    Set WSHShell = CreateObject(“WScript.Shell”)
    Set WSHNetwork = CreateObject(“WScript.Network”)

    ‘Automatically find the domain name
    Set objDomain = getObject(“LDAP://rootDse”)
    DomainString = objDomain.Get(“dnsHostName”)

    ‘Find the Windows Directory
    WinDir = WSHShell.ExpandEnvironmentStrings(“%WinDir%”)

    ‘Grab the user name
    UserName = WSHNetwork.UserName

    ‘Bind to the user object to get user name and check for group memberships
    Set UserObj = GetObject(“WinNT://” & DomainString & “/” & UserName)

    For Each GroupObj In UserObj.Groups
    If GroupObj.Name = “EASMAN-BSOP COLOR PRT” Then

    strPrinter=”\PrintServerMANPO-COLORBSOP3″
    Set WshNetwork = CreateObject(“WScript.Network”)
    Set WshShell = CreateObject(“WScript.Shell”)
    WshNetwork.AddWindowsPrinterConnection strPrinter
    WshNetwork.SetDefaultPrinter strPrinter
    MsgBox strPrinter & ” Printer connected and set as the default printer”
    Set WshNetwork = Script.CreateObject(“WScript.Network”)
    err.Clear

    Else

    WScript.Echo “You are not authorized to connect to this printer. For help contact

    your local IT Dept”

    End If
    Next

    set UserObj = Nothing
    set GroupObj = Nothing
    set WSHNetwork = Nothing
    set DomainString = Nothing
    set WSHSHell = Nothing
    Set WSHPrinters = Nothing

    wscript.quit

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.