Map Network Drive By Group Membership

Author Message
kmarty009

  • Total Posts : 65
  • Scores: 0
  • Reward points : 0
  • Joined: 5/21/2004
  • Location: USA
  • Status: offline
Map Network Drive By Group Membership Tuesday, May 17, 2005 7:11 AM (permalink)
0
I seem to have a problem mapping a drive based on AD Group Membership. I want the script to map a drive if you are a member of a certain AD Group. If you are not a memeber I want it to display a message saying you are not a member of a that group. However I am a member of the group specified in my script but it returns an error saying not a member of the group. What have I done wrong?

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: Kirk Marty
'
' AUTHOR: martyk , GTS
' DATE : 5/17/2005
'
' COMMENT:
'
'==========================================================================

'Mapping Network Drives According to User Domain

Set objNetwork = WScript.CreateObject("WScript.Network")
strUserDomain = objNetwork.UserDomain

If strUserDomain = "Domain Admins" Then
objNetwork.MapNetworkDrive "R:", "\\SPNAS1\Install", True
Else
WScript.Echo "User " & objNetwork.UserName & _
"not in Domain Admins R: will not be mapped."
End If
KirkM.
 
#1
    token

    • Total Posts : 1917
    • Scores: 0
    • Reward points : 0
    • Joined: 1/14/2005
    • Location:
    • Status: offline
    Re: Map Network Drive By Group Membership Tuesday, May 17, 2005 7:14 AM (permalink)
    0
    The UserDomain returns the domain from which the user logs on, not the group (or list of security groups) the user belongs to. To map a drive based on group membership, you can use the following function I wrote:

    Function isMemberOf(group)
    Dim user, found, temp
    found = False
    Set user = GetObject("WinNT://" & CreateObject("WScript.Network").UserDomain & "/" & CreateObject("WScript.Network").UserName & ",user")
    For Each temp In user.Groups
    WScript.Echo temp.name
    If UCase(temp.Name) = UCase(group) Then
    found = True
    Exit For
    End If
    Next
    isMemberOf = found
    End Function

    Then you can do the following.

    If isMemberOF("Domain Admins") Then
    objNetwork.MapNetworkDrive "R:", "\\SPNAS1\Install", True
    Else
    WScript.Echo "User " & objNetwork.UserName & "not in Domain Admins R: will not be mapped."
    End If


     
    #2
      kmarty009

      • Total Posts : 65
      • Scores: 0
      • Reward points : 0
      • Joined: 5/21/2004
      • Location: USA
      • Status: offline
      Re: Map Network Drive By Group Membership Tuesday, May 17, 2005 7:23 AM (permalink)
      0
      Thanks Token. However I do get an error on Line (18,1)

      Here is the error C:\scripts\test\ctxmap.vbs(18, 1) Microsoft VBScript runtime error: Object required: 'objNetwork'

      This is line 18 and I do not see a problem with the syntax?
      objNetwork.MapNetworkDrive "R:", "\\SPNAS1\Install", True

      Any advice?
       
      #3
        kmarty009

        • Total Posts : 65
        • Scores: 0
        • Reward points : 0
        • Joined: 5/21/2004
        • Location: USA
        • Status: offline
        Re: Map Network Drive By Group Membership Tuesday, May 17, 2005 7:32 AM (permalink)
        0
        Actually I fixed it. Thanks again though Token I am much obliged...
         
        #4
          token

          • Total Posts : 1917
          • Scores: 0
          • Reward points : 0
          • Joined: 1/14/2005
          • Location:
          • Status: offline
          Re: Map Network Drive By Group Membership Tuesday, May 17, 2005 11:01 AM (permalink)
          0
          No problem :)

           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9