Introduction
This utility class was written to simplify common tasks relating initially to Active Directory and SQL. It has since been updated to include file manipulation, networking and basic dates.
Background
Many of the Active Directory functions were reworked from The Code Project article by thund3rstruck.
Using the Code
Velde.Utilities
consists of several classes. Each could be split off into their own libraries.
This class requires Interop.ActiveDs.dll - included.
Active Directory - Velde.Utilities.AD
Velde.Utilities.AD AD = new Velde.Utilities.AD();
AD.debug = true;
string accountDN = AD.returnProperty("jsmith", "distinguishedName");
if(! AD.resetPasword(accountDN, "myNew$uperc001P@$$W0RD")
{
MessageBox.Show("Password was not reset!!");
}
AD.createUserAccount("cn=users,dc=test_domain,dc=local",
"klee","!Password1", "Kevin", "Lee");
AD.setProperty("klee","pwdLastSet", 0);
string kevinAccountDN = AD.returnProperty("klee", "distinguishedName");
AD.denyChangePassword(kevinAccountDN);
Database - Velde.Utilities.Database.?
Currently Supported: Access, Excel, SQL, Visual FoxPro.
Velde.Utilities.Database.SQL sql = new Velde.Utilities.Database.SQL();
sql.debug = true;
sql.server = "name or ip of server"
sql.database = "name of database";
sql.username = "username";
sql.password = "password";
sql.execQuery("SELECT * FROM table WHERE columnName LIKE 'pattern'");
for(int i=0;i<sql.dt.Rows.Count;i++)
{
Console.WriteLine(sql.dt.Rows[i]["columnName"].ToString());
}
sql.dt.Rows[rowToModify]["columnName"] = "test";
sql.updateTable(sql.da, sql.dt);
Network - Velde.Utilities.Network
Velde.Utilities.Network net = new Velde.Utilities.Network;
net.debug= true;
if(net.isAlive("IP or DNS Name"))
{
Console.WriteLine("Host is alive!");
}
if(net.isAlive("IP", 25))
{
Console.WriteLine("Server accepting connections.");
}
net.sendMail("me@mydomain.com","someone@theirDomain.com", "Subject",
"body", true/false, "serverName or IP", 25);
if(net.killHost("IP or DNS name of host"))
{
Console.WriteLine("Host accepted shutdown command.");
}
Classes Not Shown
Summary
Hopefully, this set of classes can save you some time, or give you a better idea of how to do certain tasks. Let me know if you decide to use this in any of your projects, or if you think that I'm way off base.
History
- 3-26-2008 - Article uploaded