管理本地分区
作为通过组件服务管理工具创建和配置本地分区的替代方案,可以使用特定于分区的 COM+ 管理集合和属性以编程方式管理分区。
注意
默认情况下,COM+ 分区服务未启用。 若要使用 COM+ 分区服务,必须通过组件服务管理工具或将 LocalComputer集合上的 PartitionsEnabled 属性更改为 True 才能启用。
以下用 Visual Basic 脚本编写的子例程演示如何在本地计算机上创建分区:
Sub CreatePartition (PartitonGuid, PartitionName)
Set cat = CreateObject("COMAdmin.COMAdminCatalog")
Set collPartitions = cat.GetCollection("Partitions")
collPartitions.Populate
Set part = collPartitions.Add
' If you don't specify a partition GUID, one is created for you.
' Otherwise, you can specify one this way:
part.Value("ID") = PartitonGuid
part.Value("Name") = PartitionName
collPartitions.SaveChanges
Set part = Nothing
Set collPartitions = Nothing
Set cat = Nothing
End Sub
以下用 Visual Basic 脚本编写的子例程演示如何从本地计算机中删除分区:
Sub DeletePartition (PartitionName)
Set cat = CreateObject("COMAdmin.COMAdminCatalog")
Set collPartitions = cat.GetCollection("Partitions")
collPartitions.Populate
numPartitions = collPartitions.Count
' Begin with the last partition, and work forward through the list.
For i = numPartitions - 1 To 0 Step -1
If collPartitions.Item(i).Value("Name") = PartitionName Then
collPartitions.Remove i
End If
Next
collPartitions.SaveChanges
Set collPartitions = Nothing
Set cat = Nothing
End Sub
以下用 Visual Basic 脚本编写的子例程演示如何为用户设置默认分区:
Sub SetDefaultPartitionForUser(UserName, PartitionGuid)
Set cat = CreateObject("COMAdmin.COMAdminCatalog")
Set collUsers = cat.GetCollection("PartitionUsers")
collUsers.Populate
Set user = collUsers.Add
user.Value("AccountName") = UserName
user.Value("DefaultPartitionID") = PartitionGuid
collUsers.SaveChanges
Set collUsers = Nothing
Set cat = Nothing
End Sub
以下用 Visual Basic 脚本编写的子例程演示如何为用户删除默认分区:
Sub RemoveDefaultPartitionForUser(UserName)
Set cat = CreateObject("COMAdmin.COMAdminCatalog")
Set collUsers = cat.GetCollection("PartitionUsers")
collUsers.Populate
numUsers = collUsers.Count
' Begin with the last user, and work forward through the list.
For i = numUsers - 1 To 0 Step -1
If collUsers.Item(i).Value("AccountName") = UserName Then
collUsers.Remove i
End If
Next
collUsers.SaveChanges
Set collUsers = Nothing
Set cat = Nothing
End Sub
相关主题