Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.5 KiB

  1. VERSION 5.00
  2. Begin VB.Form Form1
  3. Caption = "DistCreate"
  4. ClientHeight = 1065
  5. ClientLeft = 60
  6. ClientTop = 345
  7. ClientWidth = 2175
  8. LinkTopic = "Form1"
  9. ScaleHeight = 1065
  10. ScaleWidth = 2175
  11. StartUpPosition = 3 'Windows Default
  12. Begin VB.CommandButton Command1
  13. Caption = "Done"
  14. Height = 495
  15. Left = 360
  16. TabIndex = 0
  17. Top = 360
  18. Width = 1215
  19. End
  20. End
  21. Attribute VB_Name = "Form1"
  22. Attribute VB_GlobalNameSpace = False
  23. Attribute VB_Creatable = False
  24. Attribute VB_PredeclaredId = True
  25. Attribute VB_Exposed = False
  26. ' ------------------------------------------------------------------------
  27. ' Copyright (C) 1999 Microsoft Corporation
  28. '
  29. ' You have a royalty-free right to use, modify, reproduce and distribute
  30. ' the Sample Application Files (and/or any modified version) in any way
  31. ' you find useful, provided that you agree that Microsoft has no warranty,
  32. ' obligations or liability for any Sample Application Files.
  33. ' ------------------------------------------------------------------------
  34. Private Sub Command1_Click()
  35. End
  36. End Sub
  37. Private Sub Form_Load()
  38. On Error Resume Next
  39. ' The following code creates a distribution list and adds 2 public
  40. ' queues to the distrbution list and one private queue via a
  41. ' "msMQ-Custom-Recipient" (queue alias) which it creates.
  42. Dim contDS As IADsContainer
  43. Dim groupDist As IADsGroup
  44. Dim qinfo As New MSMQQueueInfo
  45. Dim qinfo1 As New MSMQQueueInfo
  46. Dim qinfo2 As New MSMQQueueInfo
  47. Dim iadsQueueAlias As IADs
  48. Dim contOU As IADsContainer
  49. Dim strQ2 As String
  50. Dim strBind As String
  51. Dim iGroupType As Integer
  52. Dim contRoot As IADsContainer
  53. Dim RootDSE As IADs
  54. Dim strRootDomain As String
  55. Dim sysInfo As New ADSystemInfo
  56. Dim strComputerName As String
  57. '
  58. ' Step 1 : Creating a group
  59. '
  60. ' The group will be created at the root of the local domain.
  61. ' For this we need to obtain the local domain name.
  62. ' The RootDSE is a unique entry that exists on every directory server. It
  63. ' enables you to get information about the server. Here, we will use it to
  64. ' get the domain name
  65. ' First, we will get the RootDSE object:
  66. Set RootDSE = GetObject("LDAP://RootDSE")
  67. ' Then, get the domain name :
  68. strRootDomain = RootDSE.Get("rootDomainNamingContext")
  69. ' Bind to the DS Container:
  70. strBind = "LDAP://" + strRootDomain
  71. Set contDS = GetObject(strBind)
  72. ' Create the Distribution List:
  73. Set groupDist = contDS.Create("group", "CN=NewDLGroup")
  74. 'Setting the group type to distribution list
  75. iGroupType = ADS_GROUP_TYPE_GLOBAL_GROUP
  76. groupDist.Put "sAMAccountName", "NewDLGroup"
  77. groupDist.Put "groupType", iGroupType
  78. groupDist.SetInfo
  79. '
  80. ' Step 2 : Creating 2 public queues and adding them to the DL group.
  81. '
  82. ' Creating the public queues :
  83. qinfo1.Pathname = ".\QueueName1"
  84. qinfo1.Create
  85. qinfo2.Pathname = ".\QueueName2"
  86. qinfo2.Create
  87. ' The public queues are added by their ADS paths. One way to do it
  88. ' is simply to use the property ADsPath:
  89. groupDist.Add qinfo1.ADsPath
  90. ' Another way to add a queue to the DL group is to
  91. ' set the ADS path explicitly:
  92. ' To get the computer's full AdsPath, we will use the ADSystemInfo object.The
  93. ' object lets you find information about your computer.
  94. strComputerName = sysInfo.ComputerName
  95. ' Then we can compose the name of the queue:
  96. strQ2 = "LDAP://CN=QueueName2,CN=msmq," + strComputerName
  97. ' Adding the public queue to the distribution list (these changes will
  98. ' take effect later when SetInfo will be called):
  99. groupDist.Add strQ2
  100. '
  101. ' Step 3: Create a private queue, an queue alias to the private queue,
  102. ' and adding the queue alias to the DL group.
  103. '
  104. ' in order to get the private queue's format name, we use a MSMQQueueInfo
  105. ' object.
  106. qinfo.Pathname = ".\PRIVATE$\QueueName3"
  107. qinfo.Create
  108. ' in order to add the private queue to a distribution list, what we actually do
  109. ' is create a "msMQ-Custom-Recipient" (queue alias) and make it reference the
  110. ' private queue:
  111. Set iadsQueueAlias = contDS.Create("msMQ-Custom-Recipient", "cn=QueueAliasToPrivateQueue")
  112. ' Reference the private queue :
  113. iadsQueueAlias.Put "msMQ-Recipient-FormatName", qinfo.FormatName
  114. iadsQueueAlias.SetInfo
  115. ' add the queue alias to the distribution list:
  116. groupDist.Add iadsQueueAlias.ADsPath
  117. ' save the changes to the distribution list:
  118. groupDist.SetInfo
  119. '
  120. ' Step 4: Sending a message:
  121. '
  122. ' now, send a message to the Distribution List:
  123. Dim msg As New MSMQMessage
  124. msg.Label = "This is a message"
  125. msg.Send groupDist
  126. End Sub
  127. Private Sub Form_Unload(Cancel As Integer)
  128. End
  129. End Sub