I am writing a program that will basically make a xml copy of most things in the local computer SAM store for users.
Currently it only prints a XMLElement for each user but it does not print the attributes for them.
<?xml version="1.0" encoding="utf-8"?>
<WindowsUserList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<windowsUserEntry />
<windowsUserEntry />
...
<windowsUserEntry />
<windowsUserEntry />
</WindowsUserList>
This is my main code, the check box text has formatted name for a search as its text (accounting* for example to get users accounting1, 2, 3 ect..)
windowsUserList listUsers = new windowsUserList();
PrincipalContext context = new PrincipalContext(ContextType.Machine, Settings.Default.ipAddress, Settings.Default.username, Settings.Default.password);
foreach (CheckBox cbx in groupBox1.Controls.OfType<CheckBox>())
{
if (cbx.Checked)
{
UserPrincipal usr = new UserPrincipal(context);
if (cbx.Text == "")
{
usr.Name = txtCustom.Text;
}
else
{
usr.Name = cbx.Text;
}
PrincipalSearcher search = new PrincipalSearcher(usr);
PrincipalSearchResult<Principal> results = search.FindAll();
foreach (Principal result in results)
{
listUsers.AddUser(new windowsUserEntry((UserPrincipal)result));
} // foreach (Principal result in results)
}//if (cbx.Checked)
}//foreach (CheckBox cbx in groupBox1.Controls.OfType<CheckBox>())
XmlSerializer s = new XmlSerializer(typeof(windowsUserList));
TextWriter w = new StreamWriter(dlgSave.OpenFile());
s.Serialize(w, listUsers);
w.Close();
The code for windows user list/entry is very long so I posted it to pastebin