Announcement

Collapse
No announcement yet.

Logon script with groupmembership

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logon script with groupmembership

    I am in desperate need of help with a logon script. I have this script.

    Code:
     
    Const Faelles_GROUP  = "cn=Fælles"
    Const Voksne_GROUP  = "cn=Voksne"
    Const Boern_GROUP  = "cn=Børn"
    Const IT_support_GROUP  = "cn=IT-support"
    Set wshNetwork = CreateObject("WScript.Network")
    wshNetwork.MapNetworkDrive "u:","\\hilsoeexch\" & wshNetwork.UserName
    Set ADSysInfo = CreateObject("ADSystemInfo")
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
    strGroups = LCase(Join(CurrentUser.MemberOf))
    If InStr(strGroups, Faelles_GROUP) Then
        wshNetwork.MapNetworkDrive "s:","\\hilsoedc\Fælles\"
    '    wshNetwork.AddWindowsPrinterConnection
    '    "\\PrintServer\HrLaser"
    '    wshNetWork.SetDefaultPrinter
    '    "\\PrintServer\HrLaser"
    ElseIf InStr(strGroups, Voksne_GROUP) Then
    'If InStr(strGroups, Voksne_GROUP) Then
        wshNetwork.MapNetworkDrive "v:","\\hilsoeexch\Voksne\"
    '    wshNetwork.AddWindowsPrinterConnection
    '    "\\PrintServer\FinLaser"
    '    wshNetWork.SetDefaultPrinter
    '    "\\PrintServer\FinLaser"
    ElseIf InStr(strGroups, Boern_GROUP) Then
        wshNetwork.MapNetworkDrive "s:","\\hilsoedc\Fælles\"
    '    wshNetwork.AddWindowsPrinterConnection
    '    "\\PrintServer\FinLaser"
    '    wshNetWork.SetDefaultPrinter
    '    "\\PrintServer\FinLaser"
    ElseIf InStr(strGroups, IT_Support_GROUP) Then
        wshNetwork.MapNetworkDrive "g:","\\hilsoeexch\Hilsoe Support\"
    '    wshNetwork.AddWindowsPrinterConnection
    '    "\\PrintServer\EngLaser"
    '    wshNetwork.AddWindowsPrinterConnection
    '    "\\PrintServer\Plotter"
    '    wshNetWork.SetDefaultPrinter
    '    "\\PrintServer\EngLaser"
    End If
    When I run the script the first drive is mapped, the U: drive and then nothing more happens.

  • #2
    Re: Logon script with groupmembership

    With the LCase function in this line
    strGroups = LCase(Join(CurrentUser.MemberOf))
    the variable strGroup will be totally in lowercase.

    While there are upper-case letters used in the user-defined constants in your script.

    And then, on the lines,
    (Else)If InStr(strGroups, Const) Then
    you did not make the InStr function case insensitive.



    This way it would be case insensitive:
    If InStr(1, strGroups, Const, 1) Then
    However this,
    InStr(1, Join(CurrentUser.MemberOf.MemberOf), Const, 1)
    is not the best way to determine whether or not the user is a member of a certain group: see the same note here http://forums.petri.com/showpost.php...01&postcount=2

    /Rems
    Last edited by Rems; 27th November 2011, 00:25.

    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

    Comment


    • #3
      Re: Logon script with groupmembership

      Okay that got me some of the way, but now I have a new problem. I have a user how needs 3 of the 4 group drives, but only gets one of them? How do I solve that?

      Comment


      • #4
        Re: Logon script with groupmembership

        Your ELSEIF construct is giving them one drive only
        How about a series of separate IFs so the string gets checked multiple times?
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

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

        Comment


        • #5
          Re: Logon script with groupmembership

          Can you show me an ex. I am not that good a scripting.

          Comment


          • #6
            Re: Logon script with groupmembership

            From your original example
            Code:
            Const Faelles_GROUP  = "cn=Fælles"
            Const Voksne_GROUP  = "cn=Voksne"
            Const Boern_GROUP  = "cn=Børn"
            Const IT_support_GROUP  = "cn=IT-support"
            Set wshNetwork = CreateObject("WScript.Network")
            wshNetwork.MapNetworkDrive "u:","\\hilsoeexch\" & wshNetwork.UserName
            Set ADSysInfo = CreateObject("ADSystemInfo")
            Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
            strGroups = LCase(Join(CurrentUser.MemberOf))
            If InStr(strGroups, Faelles_GROUP) Then
                wshNetwork.MapNetworkDrive "s:","\\hilsoedc\Fælles\"
            '    wshNetwork.AddWindowsPrinterConnection
            '    "\\PrintServer\HrLaser"
            '    wshNetWork.SetDefaultPrinter
            '    "\\PrintServer\HrLaser"
            End If
            If InStr(strGroups, Voksne_GROUP) Then
            'If InStr(strGroups, Voksne_GROUP) Then
                wshNetwork.MapNetworkDrive "v:","\\hilsoeexch\Voksne\"
            '    wshNetwork.AddWindowsPrinterConnection
            '    "\\PrintServer\FinLaser"
            '    wshNetWork.SetDefaultPrinter
            '    "\\PrintServer\FinLaser"
            End If
            If InStr(strGroups, Boern_GROUP) Then
                wshNetwork.MapNetworkDrive "s:","\\hilsoedc\Fælles\"
            '    wshNetwork.AddWindowsPrinterConnection
            '    "\\PrintServer\FinLaser"
            '    wshNetWork.SetDefaultPrinter
            '    "\\PrintServer\FinLaser"
            End If
            If InStr(strGroups, IT_Support_GROUP) Then
                wshNetwork.MapNetworkDrive "g:","\\hilsoeexch\Hilsoe Support\"
            '    wshNetwork.AddWindowsPrinterConnection
            '    "\\PrintServer\EngLaser"
            '    wshNetwork.AddWindowsPrinterConnection
            '    "\\PrintServer\Plotter"
            '    wshNetWork.SetDefaultPrinter
            '    "\\PrintServer\EngLaser"
            End If
            Tom Jones
            MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
            PhD, MSc, FIAP, MIITT
            IT Trainer / Consultant
            Ossian Ltd
            Scotland

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

            Comment

            Working...
            X