本文整理汇总了C#中DirectoryEntry.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.Invoke方法的具体用法?C# DirectoryEntry.Invoke怎么用?C# DirectoryEntry.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry.Invoke方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsUserInGroup
static public bool IsUserInGroup(string userName, string groupName)
{
//nugget: unfortunately, adding the current Windows User to a new Group via the Windows CompMgmt.msc GUI does not register in the WindowsIdentity data structures until after a logout/login cycle
//nugget: what i read was that the WindowsIdentity info is based on security tokens and the tokens are cached _ONLY_ at login time and is absolutely *not*refreshable* in any way other than logging out and back in
//nugget: (e.g. WindowsIdentity.GetCurrent().Groups)
//(from grp in WindowsIdentity.GetCurrent().Groups
// where grp.Translate(typeof(NTAccount)).Value.ToLower().Contains("iTRAAC_Users".ToLower())
// select 1).Count();
//nugget: especially under the oppresive yoke of Vista, it is prohibitively annoying to force a user log out/in at applicaiton install time
//nugget: and it's easily forgotten to do this up front
//nugget: so ideally we support the scenario of launching CompMgmt.msc under temporary admin credentials and adding the user to this group on the fly
//nugget: (while leaving the current user logged in to the desktop)
//nugget: this is accomplished by using the ActiveDirectory API's to pull the list of fresh group members thus avoiding the above cached token issue
string step = "";
try
{
step = "1";
//best to go after the local group and then check members so that we can handle a domain user being in our local group
var group = new DirectoryEntry("WinNT://./" + groupName + ",group"); //nugget:
step = "2";
var members = group.Invoke("members") as IEnumerable;
step = "3";
Debug.Assert(members != null, "members != null");
return (members.Cast<object>().Any(g => new DirectoryEntry(g).Name == userName));
//foreach (object group in groups) Console.WriteLine(new DirectoryEntry(group).Name);
//DirectoryEntry iTRAAC_Users = new DirectoryEntry("WinNT://./" + GroupName + ",group"); //nugget:
//IEnumerable members = iTRAAC_Users.Invoke("members") as IEnumerable; //nugget: Group.Invoke("members") worked, Group.Children was always empty
//string CurrentUserName = WindowsLoginNameSansDomain;
//foreach (object member in members) if (new DirectoryEntry(member).Name == CurrentUserName) return (true);
}
catch (/*System.Runtime.InteropServices.COMException*/ Exception ex)
{
//nugget: on my dev Win7 box, when the iTRAAC_Users group was not yet created, i'd get a nice COMException with coherent message text
//nugget: but on field Vista boxes i just get a "Uknown error (0x800708ac)" which seems to be correspond to the same thing given the Google hits
if (ex.Message.Contains("The group name could not be found")
|| ex.Message.Contains("0x800708ac")) return (false);
throw (new Exception(String.Format("Error occurred attempting to access local user/group info @step {0}\r\n\r\n{1}\r\n{2}",
step, ex.GetType(), ex.Message)));
}
}
示例2: CreateWebSite2
private void CreateWebSite2(string websname, string webpath)
{
try
{
string installPath = webpath;
string IISVirtualDirectory = websname;
var root = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
foreach (DirectoryEntry directoryEntry in root.Children)
{
if (directoryEntry.Name == IISVirtualDirectory)
{
try
{
root.Invoke("Delete", new[] { directoryEntry.SchemaClassName, IISVirtualDirectory });
root.CommitChanges();
}
catch (Exception) { }
}
}
DirectoryEntry de = root.Children.Add(IISVirtualDirectory, "IIsWebVirtualDir");
de.Properties["Path"][0] = installPath;
de.Invoke("AppCreate", true);
de.Properties["AppFriendlyName"][0] = IISVirtualDirectory;
//de.Properties["ScriptMaps"].Value = AddScriptArray();
//IIS下,将Framework自动对应到2.0版本。
Object[] mappings = (Object[])de.InvokeGet("ScriptMaps");
StringBuilder sb = new StringBuilder();
foreach (var a in mappings)
{ sb.Append(a + "\r\n"); }
ArrayList list = AddScriptArray();
de.CommitChanges();
}
catch { }
}