Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Another Login Script (Groups)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Another Login Script (Groups)

    I'm just getting my feet wet with VBScripts and I'm trying to find a cleaner way of running a command at login if a user is a member of a particular group. The code segment below works, but I'm using a lot of If's and ElseIf's and wondering if there was a nicer/cleaner way to do this?

    If InStr(strGroup, lcase(Group_Name_1)) Then
    Set wshShell = WScript.CreateObject ("") "auth.bat"
    set wshshell = nothing
    ElseIf InStr(strGroup, lcase(Group_Name_2)) Then
    Set wshShell = WScript.CreateObject ("") "auth.bat"
    set wshshell = nothing
    End If

    I have about 8 groups that I'm doing this for. Basically what I'm looking for is, if a user is in one of these groups, then run the "auth.bat" file.

  • #2
    Re: Another Login Script (Groups)

    You could use
    Or possibly rename the 8 groups so they have some common feature that no other groups have (e.g. name starts with "auth") then use instr to check (once) for that feature
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    IT Trainer / Consultant
    Ossian Ltd

    ** Remember to give credit where credit is due and leave reputation points where appropriate **


    • #3
      Re: Another Login Script (Groups)

      Create a function or sub routines in your script! Then you dont have to repeat the same code over and over.

      btw How you retrieved strGroups? can you show? Maybe that it is possible to make some changes from there of already, what could also make the script run more efficiently.

      The use of Instr() can be a problem when there are groups with contain part of the name of an other group.

      If you use ElseIf or Select Case , there is only one match possible for the user. But what should happen if the user is member of more than one of the groups you defined in the script?

      (FYI: group membership tests)


      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts


      • #4
        Re: Another Login Script (Groups)

        I found a script from another site and modified accordingly.

        ' Create objects and extract strGroup values
        Set objNetwork = CreateObject("WScript.Network")
        Set objUser = CreateObject("ADSystemInfo")
        Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
        strGroup = LCase(Join(CurrentUser.MemberOf))