Logon script with groupmembership

Home Forums Scripting Windows Script Host Logon script with groupmembership

This topic contains 5 replies, has 4 voices, and was last updated by Avatar Anonymous 7 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • Avatar
    hilsoe
    Participant
    #156915

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

    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:”,”[URL=”file://\hilsoeexch”]\hilsoeexch[/URL]” & 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:”,”[URL=”file://\hilsoedcFælles”]\hilsoedcFælles[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerHrLaser”]\PrintServerHrLaser[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerHrLaser”]\PrintServerHrLaser[/URL]”
    ElseIf InStr(strGroups, Voksne_GROUP) Then
    ‘If InStr(strGroups, Voksne_GROUP) Then
    wshNetwork.MapNetworkDrive “v:”,”[URL=”file://\hilsoeexchVoksne”]\hilsoeexchVoksne[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ElseIf InStr(strGroups, Boern_GROUP) Then
    wshNetwork.MapNetworkDrive “s:”,”[URL=”file://\hilsoedcFælles”]\hilsoedcFælles[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ElseIf InStr(strGroups, IT_Support_GROUP) Then
    wshNetwork.MapNetworkDrive “g:”,”[URL=”file://\hilsoeexchHilsoe”]\hilsoeexchHilsoe[/URL] Support”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerEngLaser”]\PrintServerEngLaser[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerPlotter”]\PrintServerPlotter[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerEngLaser”]\PrintServerEngLaser[/URL]”
    End If

    [/CODE]

    When I run the script the first drive is mapped, the U: drive and then nothing more happens.[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:”,”[URL=”file://\hilsoeexch”]\hilsoeexch[/URL]” & 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:”,”[URL=”file://\hilsoedcFælles”]\hilsoedcFælles[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerHrLaser”]\PrintServerHrLaser[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerHrLaser”]\PrintServerHrLaser[/URL]”
    ElseIf InStr(strGroups, Voksne_GROUP) Then
    ‘If InStr(strGroups, Voksne_GROUP) Then
    wshNetwork.MapNetworkDrive “v:”,”[URL=”file://\hilsoeexchVoksne”]\hilsoeexchVoksne[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ElseIf InStr(strGroups, Boern_GROUP) Then
    wshNetwork.MapNetworkDrive “s:”,”[URL=”file://\hilsoedcFælles”]\hilsoedcFælles[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerFinLaser”]\PrintServerFinLaser[/URL]”
    ElseIf InStr(strGroups, IT_Support_GROUP) Then
    wshNetwork.MapNetworkDrive “g:”,”[URL=”file://\hilsoeexchHilsoe”]\hilsoeexchHilsoe[/URL] Support”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerEngLaser”]\PrintServerEngLaser[/URL]”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “[URL=”file://\PrintServerPlotter”]\PrintServerPlotter[/URL]”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “[URL=”file://\PrintServerEngLaser”]\PrintServerEngLaser[/URL]”
    End If

    [/CODE]

    When I run the script the first drive is mapped, the U: drive and then nothing more happens.

    Rems
    Rems
    Moderator
    #228090

    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?p=249201&postcount=2

    /Rems

    Avatar
    Anonymous
    #376595

    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?

    Avatar
    Ossian
    Moderator
    #185664

    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?

    Avatar
    Anonymous
    #376596

    Re: Logon script with groupmembership

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

    Avatar
    Ossian
    Moderator
    #185666

    Re: Logon script with groupmembership

    From your original example
    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:”,”\hilsoedcFælles”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerHrLaser”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerHrLaser”
    [B]End If
    If[/B] InStr(strGroups, Voksne_GROUP) Then
    ‘If InStr(strGroups, Voksne_GROUP) Then
    wshNetwork.MapNetworkDrive “v:”,”\hilsoeexchVoksne”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerFinLaser”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerFinLaser”
    [B]End If[/B]
    [B]If[/B] InStr(strGroups, Boern_GROUP) Then
    wshNetwork.MapNetworkDrive “s:”,”\hilsoedcFælles”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerFinLaser”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerFinLaser”
    [B]End If
    If [/B]InStr(strGroups, IT_Support_GROUP) Then
    wshNetwork.MapNetworkDrive “g:”,”\hilsoeexchHilsoe Support”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerEngLaser”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerPlotter”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerEngLaser”
    End If[/CODE][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:”,”\hilsoedcFælles”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerHrLaser”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerHrLaser”
    End If
    If
    InStr(strGroups, Voksne_GROUP) Then
    ‘If InStr(strGroups, Voksne_GROUP) Then
    wshNetwork.MapNetworkDrive “v:”,”\hilsoeexchVoksne”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerFinLaser”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerFinLaser”
    End If
    If InStr(strGroups, Boern_GROUP) Then
    wshNetwork.MapNetworkDrive “s:”,”\hilsoedcFælles”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerFinLaser”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerFinLaser”
    End If
    If
    InStr(strGroups, IT_Support_GROUP) Then
    wshNetwork.MapNetworkDrive “g:”,”\hilsoeexchHilsoe Support”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerEngLaser”
    ‘ wshNetwork.AddWindowsPrinterConnection
    ‘ “\PrintServerPlotter”
    ‘ wshNetWork.SetDefaultPrinter
    ‘ “\PrintServerEngLaser”
    End If[/CODE]

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

You must be logged in to reply to this topic.