home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / ResourceKit / ADsSecurity / Exchange / MailBox / mailbox.bas next >
Encoding:
BASIC Source File  |  1999-03-15  |  3.8 KB  |  114 lines

  1. Attribute VB_Name = "Module1"
  2. Sub Main()
  3. '--------------------------------------------------------
  4. ' Security object for SD manipulation
  5. ' (REQUIRED ADSI TOOL KIT - REGSVR32 ADSSECURITY.DLL )
  6. '---------------------------------------------------------
  7. Dim sid As New ADsSID  'You can also use -- Set sid = CreateObject("ADsSID") for late binding
  8. Dim sec As New ADsSecurity 'You can also use -- Set sec = CreateObject("ADsSecurity") for late binding
  9.  
  10.  
  11. '-------------------------------------
  12. '- The rest uses ADSI Interfaces
  13. '-------------------------------------
  14. Dim sd As IADsSecurityDescriptor
  15. Dim dacl As IADsAccessControlList
  16. Dim ace As New AccessControlEntry
  17.  
  18.  
  19.  
  20. '----------------------------------------------------------------------------
  21. '--- If you don't include the ADSI 2.5 Security Type Library as you reference
  22. '--- you must manually declare the following constants
  23. '-----------------------------------------------------------------------------
  24. Const ADS_SID_HEXSTRING = 1
  25. Const ADS_SID_WINNT_PATH = 5
  26. Const ADS_RIGHT_EXCH_MODIFY_USER_ATT = &H2
  27. Const ADS_RIGHT_EXCH_MAIL_SEND_AS = &H8
  28. Const ADS_RIGHT_EXCH_MAIL_RECEIVE_AS = &H10
  29.  
  30.  
  31. '-------------------------------------------------------
  32. '-----CREATING A MAILBOX  ----------------------
  33. '--------------------------------------------------------
  34.  
  35. '---- Server, Org and Site information
  36. server = "andyhar11"
  37. Org = "MICROSOFT"
  38. Site = "INDEPENDENCE"
  39. domain = "INDEPENDENCE"
  40. userName = "andyhar"
  41. password = "passwordHere"
  42.  
  43. '--- MailBox Parameters -----
  44. strDisplayName = "Andy Harjanto"
  45. strFirstName = "Andy"
  46. strLastName = "Harjanto"
  47. strAlias = userName
  48. strMTA = "cn=Microsoft MTA,cn=" & server & ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
  49. strMDB = "cn=Microsoft Private MDB,cn=" & server & ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
  50. strSMTPAddr = "andyhar@microsoft.com"
  51.  
  52.  
  53. '------ Creating an NT user to be associated with the mail box
  54. Set dom = GetObject("WinNT://" & domain)
  55. Set usr = dom.Create("user", userName)
  56. usr.SetInfo
  57. usr.SetPassword password
  58.  
  59.  
  60. '--- Build Recipient container's adsPath that looks like this: LDAP://myserver/CN=Recipients, OU=Site, O=Org
  61. ADsPath = "LDAP://" + server
  62. ADsPath = ADsPath + "/cn=Recipients,OU="
  63. ADsPath = ADsPath + Site
  64. ADsPath = ADsPath + ",O="
  65. ADsPath = ADsPath + Org
  66.  
  67.  
  68.  
  69. Set objCont = GetObject(ADsPath)
  70.  
  71. 'Create a new MailBox
  72. Set mailBox = objCont.Create("organizationalPerson", "cn=" & strAlias)
  73. mailBox.Put "mailPreferenceOption", 0
  74. mailBox.Put "givenName", strFirstName
  75. mailBox.Put "sn", strLastName
  76. mailBox.Put "cn", strDisplayName
  77. mailBox.Put "uid", strAlias
  78. mailBox.Put "Home-MTA", strMTA
  79. mailBox.Put "Home-MDB", strMDB
  80. mailBox.Put "mail", strSMTPAddr
  81. mailBox.Put "MAPI-Recipient", True
  82. mailBox.Put "rfc822Mailbox", strSMTPAddr
  83.  
  84. '--------------------------------------------------------
  85. '  ASSOCIATING TO NT PRIMARY ACCOUNT
  86. ' (REQUIRED ADSI TOOL KIT - REGSVR32 ADSSECURITY.DLL )
  87. '---------------------------------------------------------
  88. sid.SetAs ADS_SID_WINNT_PATH, "WinNT://" & domain & "/" & strAlias & ",user"
  89. sidHex = sid.GetAs(ADS_SID_HEXSTRING)
  90. mailBox.Put "Assoc-NT-Account", sidHex
  91.  
  92. ' Commit the property cache to the directory service
  93. mailBox.SetInfo
  94.  
  95.  
  96.  
  97. '-------------------------------------------------
  98. '--- SET THE MAIL BOX SECURITY ------------------
  99. '-- To allow the user to modify user attribute, send mail and receive mail
  100. '-------------------------------------------------
  101. Set sd = sec.GetSecurityDescriptor(mailBox.ADsPath)
  102. Set dacl = sd.DiscretionaryAcl
  103. ace.Trustee = domain & "\" & strAlias
  104. ace.AccessMask = ADS_RIGHT_EXCH_MODIFY_USER_ATT Or ADS_RIGHT_EXCH_MAIL_SEND_AS Or ADS_RIGHT_EXCH_MAIL_RECEIVE_AS
  105. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
  106. dacl.AddAce ace
  107. sd.DiscretionaryAcl = dacl
  108. sec.SetSecurityDescriptor sd
  109.  
  110.   
  111.  
  112.  
  113. End Sub
  114.