我希望知道使用C#以编程方式将COM(“Machine_Name”\ IIS_IUSRS)添加到COM +组件中的用户角色的方法。因此,无论何时安装我的COM +组件,都会在Role。
下创建ASP.NET用户答案 0 :(得分:5)
这是代码。你必须引用C:\ windows \ system32 \ com \ comadmin.dll。
using System;
using COMAdmin;
using Microsoft.VisualBasic;
namespace TesteAdicionaRole
{
class Program
{
static void Main(string[] args)
{
string packageName = "TRICOLOR";
ICOMAdminCatalog catalog = (ICOMAdminCatalog)Interaction.CreateObject("COMAdmin.COMAdminCatalog", string.Empty);
ICatalogCollection packages = (ICatalogCollection)catalog.GetCollection("Applications");
packages.Populate();
foreach (ICatalogObject package in packages)
if (package.Name.ToString().Equals(packageName))
{
ICatalogCollection roles = (ICatalogCollection)packages.GetCollection("Roles", package.Key);
roles.Populate();
ICatalogObject role = (ICatalogObject)roles.Add();
role.set_Value("Name", "MyRoleName");
roles.SaveChanges();
ICatalogCollection users = (ICatalogCollection)roles.GetCollection("UsersInRole", role.Key);
users.Populate();
ICatalogObject user = (ICatalogObject)users.Add();
user.set_Value("User", "MV0266\\IUSR_MV0266");
users.SaveChanges();
break;
}
}
}
}
[]的