Another Login Script (Groups)

Home Forums Scripting Windows Script Host Another Login Script (Groups)

This topic contains 3 replies, has 3 voices, and was last updated by Avatar jp1 9 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    jp1
    Member
    #149394

    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 (“WSCript.shell”)
    wshshell.run “auth.bat”
    set wshshell = nothing
    ElseIf InStr(strGroup, lcase(Group_Name_2)) Then
    Set wshShell = WScript.CreateObject (“WSCript.shell”)
    wshshell.run “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.
    Thanks

    Avatar
    Ossian
    Moderator
    #181579

    Re: Another Login Script (Groups)

    You could use select…case
    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

    Rems
    Rems
    Moderator
    #227732

    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.

    Notes,
    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)

    Rems

    Avatar
    jp1
    Member
    #297370

    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))

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.