Click here to Skip to main content
12,402,202 members (67,161 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

34.6K views
676 downloads
40 bookmarked
Posted

UserManager: a class to manipulate local Windows users and groups

, 2 Aug 2006 CPOL
UserManager was built to simplify local users and groups manipulation
localuser
bin
Release
localuser.exe
localuser.pdb
localuser.vshost.exe
UserManager.dll
UserManager.pdb
localuser.csproj.user
Properties
UserManager.suo
localuser.suo
UserManager
bin
Release
UserManager.dll
UserManager.pdb
Properties
UserManager.csproj.user
UserManager1.1
bin
Release
UserManager1.1.dll
UserManager1.1.csproj.user
UserManager1.1.suo
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)

Share

About the Author

Massimo Beatini
Web Developer
Italy Italy
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 2 Aug 2006
Article Copyright 2006 by Massimo Beatini
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid