Click here to Skip to main content
15,881,812 members
Articles / Programming Languages / C#

UserManager: a class to manipulate local Windows users and groups

Rate me:
Please Sign up or sign in to vote.
4.71/5 (12 votes)
2 Aug 2006CPOL 48.4K   754   40  
UserManager was built to simplify local users and groups manipulation
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MBeatini
{
    public partial class FormAddUser : Form
    {
        public FormAddUser()
        {
            InitializeComponent();

            // fill the combobox
            UserManager um = new UserManager();
            ArrayList al = um.ListGroupsInServer();
            al.Sort();
            for (int i = 0; i < al.Count; i++)
                comboBox1.Items.Add(al[i]);
            um = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("Username: mandatory field!", "Warning", MessageBoxButtons.OK);
                textBox1.Focus();
            }
            else if (textBox2.Text.Trim().Length == 0)
            {
                MessageBox.Show("Password: mandatory field!", "Warning", MessageBoxButtons.OK);
                textBox1.Focus();
            }
            else
            {
                UserManager um = new UserManager();
                if (!um.AddUser(textBox1.Text, textBox2.Text, textBox3.Text, comboBox1.SelectedItem.ToString()))
                    MessageBox.Show(um.ErrorMessage, "Warning", MessageBoxButtons.OK);
                else
                    MessageBox.Show("User " + textBox1.Text + " created", "Warning", MessageBoxButtons.OK);

                um = null;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions