本文整理汇总了C#中System.DirectoryServices.DirectoryEntry.CommitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.CommitChanges方法的具体用法?C# DirectoryEntry.CommitChanges怎么用?C# DirectoryEntry.CommitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry.CommitChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewUnit
/// <summary>
/// 在根目录下创建组织单元
/// </summary>
/// <param name="ou">组织单元名称</param>
/// <returns></returns>
public bool CreateNewUnit(string ou,string ouName)
{
bool result=false;
///获得创建DirectoryEntry 的父对象
string LDAPDomain ="/"+ Iadc.GetLDAPDomain();
DirectoryEntry oDE= Iadc.GetDirectoryObject(LDAPDomain);
DirectoryEntry oDEC=new DirectoryEntry();
//校验是否存在全局同名的组织单元
if(!Iadch.CheckUnit(ou))
{
try
{
//创建子组织单元
oDEC=oDE.Children.Add("OU="+ou,"organizationalunit");
oDEC.Properties["description"].Value=ouName;
oDEC.Properties["l"].Value="1";
oDEC.CommitChanges();
result=true;
}
catch(Exception err)
{
result=false;
}
}
return result;
}
示例2: ChangePassword
/// <summary>
/// �������û�������
/// </summary>
/// <param name="UserName">���û���</param>
/// <param name="OldPassword">������</param>
/// <param name="NewPassword">������</param>
/// <param name="DomainName">DNS����</param>
/// <returns>�ɹ������棬���ɹ����ؼ�</returns>
public static bool ChangePassword(string UserName, string OldPassword, string NewPassword, string DomainName)
{
try
{
string UserPrincipalName = UserName + "@" + DomainName;
DirectoryEntry deRootDSE = new DirectoryEntry("LDAP://RootDSE", UserPrincipalName, OldPassword, AuthenticationTypes.Secure);
DirectoryEntry deDomain = new DirectoryEntry("LDAP://" + deRootDSE.Properties["defaultNamingContext"].Value.ToString(), UserPrincipalName, OldPassword, AuthenticationTypes.Secure);
DirectorySearcher dsSearcher = new DirectorySearcher();
dsSearcher.SearchRoot = deDomain;
dsSearcher.SearchScope = SearchScope.Subtree;
dsSearcher.Filter = "(userPrincipalName=" + UserPrincipalName + ")";
SearchResult srResult = dsSearcher.FindOne();
if (srResult != null)
{
DirectoryEntry deUser = new DirectoryEntry(srResult.GetDirectoryEntry().Path, UserPrincipalName, OldPassword, AuthenticationTypes.Secure);
deUser.Invoke("ChangePassword", new object[] { OldPassword, NewPassword });
deUser.CommitChanges();
return true;
}
else
return false;
}
catch //(Exception ex)
{
return false;// ex.Message;
}
}
示例3: change
public bool change(string username,string newpassword)
{
//Method to change the password of the remote machine
DirectoryEntry dirEntry = null;
string computerName = @"WinNT://" + this.target + "/" + username + ",user";
try
{
dirEntry = new DirectoryEntry(computerName, this.adUser, this.adPassword);
dirEntry.Invoke("SetPassword", new Object[] { newpassword});
dirEntry.CommitChanges();
try
{
this.displayPopupInRemote();
}
catch (Exception e)
{
this.setError("Unable to Display Message in Remote Machine - " +e.Message);
}
return true;
}
catch (Exception Ex)
{
this.setError(Ex.Message);
}
finally
{
if (dirEntry != null)
dirEntry.Dispose();
}
return false;
}
示例4: btnEdit_Click
private void btnEdit_Click(object sender, EventArgs e)
{
btnEdit.Enabled = false;
DirectoryEntry dir = new DirectoryEntry("IIS://localhost/w3svc");
dir.Properties["AspMaxRequestEntityAllowed"].Value = AspMaxRequestEntityAllowed.Text;
dir.Properties["DefaultDoc"].Value = DefaultDoc.Text;
dir.Properties["LogFileDirectory"].Value = LogFileDirectory.Text;
dir.Properties["AspEnableParentPaths"].Value = AspEnableParentPaths.Checked;
dir.Properties["ScriptMaps"].Value = Comm.GetScriptMaps(ScriptMaps.Text);
dir.CommitChanges();
SET_GZIP(GZIP.Checked, txtGzipPath.Text.Trim());
SetMimeTypeProperty("IIS://localhost/MimeMap", ".flv", "flv-application/octet-stream", FLV.Checked);
DirectoryEntry dir2 = new DirectoryEntry("IIS://localhost");
dir2.Properties["EnableEditWhileRunning"].Value = EnableEditWhileRunning.Checked ? "1" : "0";
dir2.CommitChanges();
dir2.Invoke("SaveData", new object[0]);//保存配置到MetaBase.xml
//dir2.Invoke("Backup", new object[3]{"haha", 1,1});
//dir2.Invoke("Backup", new object[3] { "haha", 2, 1 });
//dir2.Invoke("Backup", new object[3] { "haha", 3, 2 });
//dir2.Invoke("Backup", new object[3] { "haha2", 1,1 });
//dir2.Invoke("Restore",new object[3] { "haha2", 1,0 });
btnEdit.Enabled = true;
MessageBox.Show("OK");
}
示例5: SetProperties
public static void SetProperties(DirectoryEntry objectDE, Dictionary<string, object> properties)
{
if (objectDE == null)
{
throw new NullReferenceException("Parametr <objectDE> cannot be null");
}
if (properties == null)
{
throw new NullReferenceException("Parametr <properties> cannot be null");
}
foreach (var _key in properties.Keys) {
try
{
switch (_key)
{
case "info":
case "extensionAttribute1":
objectDE.Properties[_key].Value = (string)properties[_key];
break;
}
objectDE.CommitChanges();
}
catch(Exception ex)
{
throw new Exception("Cannot set DirectoryEntry property <" + _key + ">");
}
}
}
示例6: CreateVirtualDir
public static void CreateVirtualDir(string virtualdirname, string logicDir)
{
DirectoryEntry rootEntry;
rootEntry = new DirectoryEntry("IIS://localhost/W3SVC/1/root");
DirectoryEntry newVirDir;
newVirDir = rootEntry.Children.Add(virtualdirname, "IIsWebVirtualDir");
newVirDir.Invoke("AppCreate", true);
newVirDir.CommitChanges();
rootEntry.CommitChanges();
newVirDir.Properties["AnonymousPasswordSync"][0] = true;
newVirDir.Properties["Path"][0] = logicDir;//+ @"virtualdirentry\virtualname\";
//设置的端口绑定数据
//_newVirDir.Properties["ServerBindings"].Value =AppEntitys.WebAppInfor.HostIp+AppEntitys.WebAppInfor.HostProt+AppEntitys.WebAppInfor.AppDesc;
//设置起始默认页:
newVirDir.Properties["EnableDefaultDoc"][0] = true;
newVirDir.Properties["DefaultDoc"][0] = "Default.aspx";
//_newVirDir
newVirDir.CommitChanges();
}
示例7: SetPropertyValue
protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext)
{
string srcPropertyValue = GetNormalizeddSourceValue(srcOguObject, srcPropertyName, context);
string targetPropertyValue = GetNormalizeddTargetValue(entry, targetPropertyName, context);
if (srcPropertyValue != targetPropertyValue)
{
//entry.CommitChanges();
try
{
entry.Properties[targetPropertyName].Value = srcOguObject.Properties[srcPropertyName];
// entry.CommitChanges();
}
catch (DirectoryServicesCOMException ex)
{
if (ex.ErrorCode == -2147019886)
{
//对象已存在
entry.Properties[targetPropertyName].Value = "TMP" + Environment.TickCount.ToString("X");
entry.CommitChanges();
SynchronizeContext.Current.DelayActions.Add(new DelayRenameCodeNameAction(srcOguObject, srcPropertyName, entry.NativeGuid, targetPropertyName));
}
else
{
throw;
}
}
}
}
示例8: AddUserToLocalGroup
protected bool AddUserToLocalGroup(string user, string groupName, string domainName, string machine)
{
bool reponse = false;
try
{
string userPath = string.Format("WinNT://{0}/{1},user", domainName, user);
string groupPath = string.Format("WinNT://{0}/{1},group", machine, groupName);
using (DirectoryEntry groupe = new DirectoryEntry(groupPath))
{
groupe.Invoke("Add", userPath);
groupe.CommitChanges();
groupe.Close();
}
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
Log(Level.Error, E.Message.ToString());
}
return reponse;
}
示例9: CreateSite
public void CreateSite(string port, string siteName, string siteExplain, string defaultDoc)
{
DirectoryEntry de = new DirectoryEntry("IIS://localhost/" + "w3svc"); //从活动目录中获取IIS对象。
object[] prams = new object[2] { "IIsWebServer", Convert.ToInt32(siteName) };
DirectoryEntry site = (DirectoryEntry)de.Invoke("Create", prams); //创建IISWebServer对象。
site.Properties["KeyType"][0] = "IIsWebServer";
site.Properties["ServerComment"][0] = siteExplain; //站点说明
site.Properties["ServerState"][0] = 2; //站点初始状态,1.停止,2.启动,3
site.Properties["ServerSize"][0] = 1;
site.Properties["ServerBindings"].Add(":" + port + ":"); //站点端口
site.CommitChanges(); //保存改变
de.CommitChanges();
DirectoryEntry root = site.Children.Add("Root", "IIsWebVirtualDir"); //添加虚拟目录对象
root.Invoke("AppCreate", true); //创建IIS应用程序
root.Properties["path"][0] = @"D:\IISmanage"; //虚拟目录指向的物理目录
root.Properties["EnableDirBrowsing"][0] = false;//目录浏览
root.Properties["AuthAnonymous"][0] = false;
root.Properties["AccessExecute"][0] = false; //可执行权限
root.Properties["AccessRead"][0] = true;
root.Properties["AccessWrite"][0] = true;
root.Properties["AccessScript"][0] = true;//纯脚本
root.Properties["AccessSource"][0] = false;
root.Properties["FrontPageWeb"][0] = false;
root.Properties["KeyType"][0] = "IIsWebVirtualDir";
root.Properties["AppFriendlyName"][0] = siteExplain; //应用程序名
root.Properties["AppIsolated"][0] = 2;
root.Properties["DefaultDoc"][0] = defaultDoc; //默认文档
root.Properties["EnableDefaultDoc"][0] = true; //是否启用默认文档
root.CommitChanges();
site.CommitChanges();
root.Close();
site.Close();
de.CommitChanges(); //保存
site.Invoke("Start", null); //除了在创建过程中置初始状态外,也可在此调用方法改变状态
}
示例10: RemoveUserFromGroup
public void RemoveUserFromGroup(string userDn, string groupDn)
{
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + groupDn);
dirEntry.Properties["member"].Remove(userDn);
dirEntry.CommitChanges();
dirEntry.Close();
}
示例11: CreateVirtualDirectory
static void CreateVirtualDirectory(string parentPath, string name, string homeDirectory, string[] remainingPaths)
{
name = name.Trim('/');
using (var parent = new DirectoryEntry(parentPath))
{
string existingChildPath = null;
foreach (var child in parent.Children.OfType<DirectoryEntry>())
{
if (child.SchemaClassName == "IIsWebVirtualDir" && child.Name.ToLowerInvariant() == name.ToLowerInvariant())
{
existingChildPath = child.Path;
}
child.Close();
}
if (existingChildPath == null)
{
var child = parent.Children.Add(name.Trim('/'), "IIsWebVirtualDir");
child.Properties["Path"][0] = homeDirectory;
child.CommitChanges();
parent.CommitChanges();
existingChildPath = child.Path;
child.Close();
}
if (remainingPaths.Length > 0)
{
CreateVirtualDirectory(existingChildPath, remainingPaths.First(), homeDirectory, remainingPaths.Skip(1).ToArray());
}
}
}
示例12: AddUserToGroup
/// <summary>
/// Adds a user to a group.
/// </summary>
/// <param name="userName">Name of the user.</param>
/// <param name="groupName">Name of the group.</param>
public static void AddUserToGroup(string userName, string groupName)
{
using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./" + groupName + ",Group"))
{
groupEntry.Invoke("Add", new object[] { "WinNT://" + userName + ",User" });
groupEntry.CommitChanges();
}
}
示例13: AddLocalUserToLocalGroup
//3. Добавление пользователя в группу:
public static void AddLocalUserToLocalGroup(string userName, string groupName)
{
string groupPath = string.Format("WinNT://{0}/{1},group", Environment.MachineName, groupName);
string userPath = string.Format("WinNT://{0}/{1},user", Environment.MachineName, userName);
var root = new DirectoryEntry(groupPath);
root.Invoke("Add", new object[] { userPath });
root.CommitChanges();
}
示例14: DisallowOverlappingRotation
public void DisallowOverlappingRotation(string applicationPoolName)
{
using (var applicationPool = new DirectoryEntry(string.Format("{0}/{1}", ApplicationPoolsEntry, applicationPoolName)))
{
applicationPool.Properties["DisallowOverlappingRotation"].Value = true;
applicationPool.CommitChanges();
}
}
示例15: DeleteApplication
public void DeleteApplication()
{
var directoryEntry =
new DirectoryEntry(
String.Concat(new object[] {"IIS://localhost/W3SVC/", _iWebServerID, "/ROOT", _sPath, "/", _sName}));
directoryEntry.Invoke("AppDelete", new object[0]);
directoryEntry.CommitChanges();
}