Thursday

C#:ActiveDirectory : Check User cannot change password

in project add COM reference to "Active DS Type Library" COM library v1.0
usually located in C:\WINDOWS\system32\activeds.tlb.


using ActiveDs;
public void CheckUserCanChangePasswordsProperty()
{
DirectoryEntry de = GetDirectoryObject(UserName);
string PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}";
string[] trustees = { "NT AUTHORITY\\SELF", "EVERYONE" };


ActiveDs.IADsSecurityDescriptor sd =
(ActiveDs.IADsSecurityDescriptor)de.Properties["ntSecurityDescriptor"].Value;
ActiveDs.IADsAccessControlList acl = (ActiveDs.IADsAccessControlList)sd.DiscretionaryAcl;
ActiveDs.AccessControlEntry ace = new ActiveDs.AccessControlEntry();


double denied = (double)ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_DENIED_OBJECT;
double objectType = (double)ActiveDs.ADS_FLAGTYPE_ENUM.ADS_FLAG_OBJECT_TYPE_PRESENT;
double dsControl = (double)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_DS_CONTROL_ACCESS;

foreach (string trustee in trustees)
{
ace.Trustee = trustee;
ace.AceFlags = 0;
ace.AceType = Convert.ToInt32(Math.Floor(denied));
ace.Flags = Convert.ToInt32(Math.Floor(objectType));
ace.ObjectType = PASSWORD_GUID;
ace.AccessMask = Convert.ToInt32(Math.Floor(dsControl));

acl.AddAce(ace);
}
sd.DiscretionaryAcl = acl;
de.Properties["ntSecurityDescriptor"].Value = sd;

de.CommitChanges();
}

more...

C#:Active Directory:Uncheck User cannot change password


public void SetUserCanChangePasswordsPropertyUncheck()
{
DirectoryEntry de = GetDirectoryObject(UserName);
string PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}";
ActiveDs.IADsSecurityDescriptor sd =
(ActiveDs.IADsSecurityDescriptor)de.Properties["ntSecurityDescriptor"].Value;
ActiveDs.IADsAccessControlList acl = (ActiveDs.IADsAccessControlList)sd.DiscretionaryAcl;
//ActiveDs.AccessControlEntry ace = new ActiveDs.AccessControlEntry();
ActiveDs.ADS_ACETYPE_ENUM aceType;

//look for existing ace and get rid of
foreach (ActiveDs.AccessControlEntry ace in acl)
{
if (!(ace.ObjectType == null) && ace.ObjectType.ToLower() == PASSWORD_GUID)
{
if (ace.Trustee == "Everyone")
{
acl.RemoveAce(ace);
de.CommitChanges();
}
else if (ace.Trustee == "NT AUTHORITY\\SELF")
{
acl.RemoveAce(ace);
de.CommitChanges();
}
}
}

//now put in the one we want
sd.DiscretionaryAcl = acl;
de.Properties["ntSecurityDescriptor"].Value = sd;
de.CommitChanges();
}

more...

C#:Active Directory:Check/Uncheck Password never expires


public void SetPasswordNeverExpiresProperty(bool PasswordNeverExpires)
{
DirectoryEntry de = GetDirectoryObject(UserName);
if (PasswordNeverExpires)
{
ActiveDirectoryHelper.SetProperty(de, "userAccountControl",
(int)de.Properties["userAccountControl"].Value | 0x10000);
}
else
{
ActiveDirectoryHelper.SetProperty(de, "userAccountControl",
(int)de.Properties["userAccountControl"].Value ^ 0x10000);
}
de.CommitChanges();
}

more...

C#:Active Directory:Check/Uncheck User must change password at next logon



public void SetuserHasToChangePasswordsInTheNextLoginProperty(bool userHasToChangePasswordsInTheNextLogin)
{
DirectoryEntry de = GetDirectoryObject(UserName);
if (userHasToChangePasswordsInTheNextLogin)
{
ActiveDirectoryHelper.SetProperty(de, "pwdLastSet", 0);
}
else
{
ActiveDirectoryHelper.SetProperty(de, "pwdLastSet", -1);
}
de.CommitChanges();
}

more...

treeview .net control style



<table> <tr> <td style="border: solid 1px;">
<div style="overflow:scroll;height:200px">
<asp:TreeView PopulateNodesFromClient = "true" EnableClientScript = "true"
ID="WebTreeView1" runat="server" ShowCheckBoxes="Leaf" Width="100%"
NodeStyle-ForeColor="DarkBlue"
NodeStyle-Font-Names="Verdana"
NodeStyle-Font-Size="8pt"
NodeStyle-HorizontalPadding="5"
NodeStyle-VerticalPadding="0"
NodeStyle-BorderColor="#FFFFFF"
NodeStyle-BorderStyle="solid"
NodeStyle-BorderWidth="0px"
RootNodeStyle-Font-Bold="true"
SelectedNodeStyle-BackColor="#cccccc"
SelectedNodeStyle-BorderColor="#888888"
SelectedNodeStyle-BorderStyle="solid"
SelectedNodeStyle-BorderWidth="0px"
ShowLines="True"
NodeIndent="15"
ExpandDepth="1"
PathSeparator="|"
>
</asp:TreeView>
</div>
</td></tr></table>

more...

asp.net treeview load expanded and keep selection

 

TreeNode newNode = new TreeNode();
string title=string.Format("{0};{1};{2};{3}", row["Field1"], row["Field2"], row["Field3"], row["Field4"]);
newNode.Text=string.Format("<input type='hidden' value='{0}'><span title='{0}' onclick='return false;'>{1}</span>;",title,Bezeichnung);
string val=string.Format("{0}",row["NameGroupID"]);
newNode.Value =val;
newNode.Checked=stored.Contains(val);
newNode.Expand();
ProduktbereichNode.ChildNodes.Add(newNode);

more...

asp.net treeview javascript search

Backward search:
 

function SearchBack(tv_id,str)
{
var tree = document.getElementById(tv_id);
var treeLinks = tree.getElementsByTagName('A');
eval(' var sel_name = '+tv_id+'_Data.selectedNodeID.value;');
var elem;
var sel_passed=0;
for(var element in treeLinks )
{
var sub1=treeLinks[element].firstChild;

if (sel_name && treeLinks[element].id==sel_name) {
sel_passed =1;
if (!sel_name || sel_passed==1) break;
}
if (sub1 && (''+sub1.value).indexOf(str) >=0)
{
//log("found"+treeLinks[element].id);
elem=treeLinks[element];
}
}

if (elem) {
eval('TreeView_SelectNode('+tv_id+'_Data,elem,"'+elem.id+'");');
elem.focus();
}else{
alert('Not found');
}
}


Forward search:
 

function SearchForward(tv_id,str)
{
var tree = document.getElementById(tv_id);
var treeLinks = tree.getElementsByTagName('A');
eval(' var sel_name = '+tv_id+'_Data.selectedNodeID.value;');
var elem;
var sel_passed=0;
for(var element in treeLinks)
{
var sub1=treeLinks[element].firstChild;
if (sub1 && (''+sub1.value).indexOf(str) >=0)
{
//log("found"+treeLinks[element].id);
elem=treeLinks[element];
if (!sel_name || sel_passed==1) break;
}

if (sel_name && treeLinks[element].id==sel_name) {
sel_passed =1;
}
}
if (elem) {
eval('TreeView_SelectNode('+tv_id+'_Data,elem,"'+elem.id+'");');
elem.focus();
} else{
alert('Not found');
}


}

Saturday

Add Winmerge to TortoiseHg as default merge tool

1.Right mouse click on repository, select TortoiseHg >> Global setting
2.in Open Dialog select "User Global Setting" and Click "Edit"
3.Add these two lines at end of file :

[extdiff]
cmd.winmerge = C:\Program Files\WinMerge\WinMerge.exe
opts.winmerge = /e /x /ub /wl

4.Now run the Global Settings tool. On the TortoiseHg tab, you should see winmerge available
in the drop-down list for Visual Diff Command. Select winmerge, apply, then close.


more...

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...