Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_connect_network_drives_based_on_group_membership.vbs

(view source code of login_connect_network_drives_based_on_group_membership.vbs as plain text)

  1. strGroup  = "Marketing"
  2. blnMember = False
  3.  
  4. Set objSysInfo = CreateObject( "WinNTSystemInfo" )
  5. strUserName = objSysInfo.UserName
  6. strDomain   = objSysInfo.DomainName
  7. Set objSysInfo = Nothing
  8.  
  9. Set objUser   = GetObject( "WinNT://" & strDomain & "/" & strUserName )
  10. Set colGroups = objUser.Groups
  11.  
  12. For Each objGroup in colGroups
  13. 	If LCase( objGroup.Name ) = LCase( strGroup ) Then
  14. 		blnMember = True
  15. End If
  16. Next
  17.  
  18. Set colGroups = Nothing
  19. set objUser   = Nothing
  20.  
  21. If blnMember Then
  22. 	Set wshNetwork = CreateObject( "WScript.Network" )
  23. 	On Error Resume Next
  24. 	With wshNetwork
  25. 		.MapNetworkDrive "G:", "\\CompanyServer\Dept"
  26. 		If Err Then
  27. 			WScript.Echo "Error " & Err & " mapping drive G:"
  28. 			WScript.Echo "(" & Err.Description & ")"
  29. 		End If
  30.  
  31. 		.MapNetworkDrive "H:", "\\CompanyServer\" & .UserName
  32. 		If Err Then
  33. 			WScript.Echo "Error " & Err & " mapping drive H:"
  34. 			WScript.Echo "(" & Err.Description & ")"
  35. 		End If
  36. 	End With
  37. 	On Error Goto 0
  38. 	Set wshNetwork = Nothing
  39. End If

page last modified: 2022-10-20