本文整理汇总了C#中System.DirectoryServices.AccountManagement.UserPrincipal.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# UserPrincipal.Delete方法的具体用法?C# UserPrincipal.Delete怎么用?C# UserPrincipal.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.AccountManagement.UserPrincipal
的用法示例。
在下文中一共展示了UserPrincipal.Delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_Creating_Home_Directory__Then_It_Should_Have_The_Appropriate_Rights
public void When_Creating_Home_Directory__Then_It_Should_Have_The_Appropriate_Rights()
{
var username = string.Format("testUser{0}", DateTime.Now.Millisecond);
var administration = new AdministrationService();
var context = new PrincipalContext(ContextType.Machine);
var user = new UserPrincipal(context)
{
Name = username,
UserCannotChangePassword = false,
PasswordNeverExpires = true,
};
user.SetPassword("!Password123");
user.Save();
GroupPrincipal grp = GroupPrincipal.FindByIdentity(context, "IIS_IUSRS");
if (grp != null)
{
grp.Members.Add(user);
grp.Save();
}
Assert.IsNotNull(grp);
string dir = Path.Combine(ConfigurationManager.AppSettings["HomeDirectory"], username);
administration.MkDir(username, dir);
bool exists = Directory.Exists(dir);
Assert.IsTrue(exists);
Directory.Delete(dir);
user.Delete();
}
示例2: RemoveWindowsAccount
public void RemoveWindowsAccount(UserPrincipal user)
{
try
{
user.Delete();
BatchState.State = UserProcessState.WIN_DELETE_OK;
}
catch (Exception)
{
BatchState.State = UserProcessState.WIN_DELETE_ERROR;
throw;
}
}
示例3: When_Creating_New_Site__It_Should_Be_Present_In_IIS
public void When_Creating_New_Site__It_Should_Be_Present_In_IIS()
{
var username = string.Format("testUser{0}", DateTime.Now.Millisecond);
const string password = "!Password123";
var administration = new AdministrationService();
var context = new PrincipalContext(ContextType.Machine);
var user = new UserPrincipal(context) {
Name = username,
UserCannotChangePassword = false,
PasswordNeverExpires = true,
};
user.SetPassword(password);
user.Save();
var grp = GroupPrincipal.FindByIdentity(context, "IIS_IUSRS");
if (grp != null)
{
grp.Members.Add(user);
grp.Save();
}
Assert.IsNotNull(grp);
var dir = Path.Combine(ConfigurationManager.AppSettings["HomeDirectory"], username);
var info = Directory.CreateDirectory(dir);
var security = info.GetAccessControl();
security.AddAccessRule(new FileSystemAccessRule(username,
FileSystemRights.Read |
FileSystemRights.Write |
FileSystemRights.Modify |
FileSystemRights.CreateDirectories |
FileSystemRights.CreateFiles |
FileSystemRights.ReadAndExecute,
InheritanceFlags.ContainerInherit |
InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
info.SetAccessControl(security);
var server = new IisServer();
// In order to make this work, you will have to add an entry to your host file or dns...
const string fqdn = "www.test.com";
server.AddWebSite(username, password, fqdn, dir, "http", string.Format("*:80:{0}", fqdn));
using (var serverManager = new ServerManager())
{
var site = serverManager.Sites.FirstOrDefault(x => x.Name == fqdn);
Assert.IsNotNull(site);
var app = site.Applications.FirstOrDefault();
Assert.IsNotNull(app);
var pool = serverManager.ApplicationPools.FirstOrDefault(x => x.Name == fqdn);
Assert.IsNotNull(pool);
// Cleaning up...
app.Delete();
site.Delete();
pool.Delete();
serverManager.CommitChanges();
}
// Cleaning up...
Directory.Delete(dir, true);
user.Delete();
}
示例4: EliminarUsuario
/// <summary>
/// Elimina un usuario
/// </summary>
/// <param name="usuario">Usuario a eliminar</param>
public void EliminarUsuario(UserPrincipal usuario)
{
usuario.Delete();
}