Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

UserManager: a class to manipulate local Windows users and groups

, 2 Aug 2006
UserManager was built to simplify local users and groups manipulation
usermanager_source_and_demo.zip
localuser
bin
Release
localuser.exe
localuser.pdb
localuser.vshost.exe
UserManager.dll
UserManager.pdb
localuser.csproj.user
Properties
Settings.settings
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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;

namespace MBeatini
{
    public partial class FormOptions : Form
    {
        private HybridDictionary list = new HybridDictionary();

        public FormOptions(int op)
        {
            InitializeComponent();
            if (op == 1)
            {
                this.Text = "Add options";
                button2.Visible = false;
            }
            else
            {
                this.Text = "Remove options";
                button1.Visible = false;
            }


            list.Add("UF_TEMP_DUPLICATE_ACCOUNT", 0x0100);
            list.Add("UF_NORMAL_ACCOUNT", 0x0200);
            list.Add("UF_INTERDOMAIN_TRUST_ACCOUNT", 0x0800);
            list.Add("UF_WORKSTATION_TRUST_ACCOUNT", 0x1000);
            list.Add("UF_SERVER_TRUST_ACCOUNT", 0x2000);
            list.Add("UF_DONT_EXPIRE_PASSWD", 0x10000);
            list.Add("UF_SCRIPT", 0x0001);
            list.Add("UF_ACCOUNTDISABLE", 0x0002);
            list.Add("UF_HOMEDIR_REQUIRED", 0x0008);
            list.Add("UF_LOCKOUT", 0x0010);
            list.Add("UF_PASSWD_NOTREQD", 0x0020);
            list.Add("UF_PASSWD_CANT_CHANGE", 0x0040);
            list.Add("UF_ACCOUNT_LOCKOUT", 0x0010);
            list.Add("UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED", 0x0080);


            comboBox1.Items.Add("UF_TEMP_DUPLICATE_ACCOUNT");
            comboBox1.Items.Add("UF_NORMAL_ACCOUNT");
            comboBox1.Items.Add("UF_INTERDOMAIN_TRUST_ACCOUNT");
            comboBox1.Items.Add("UF_WORKSTATION_TRUST_ACCOUNT");
            comboBox1.Items.Add("UF_SERVER_TRUST_ACCOUNT");
            comboBox1.Items.Add("UF_DONT_EXPIRE_PASSWD");
            comboBox1.Items.Add("UF_SCRIPT");
            comboBox1.Items.Add("UF_ACCOUNTDISABLE");
            comboBox1.Items.Add("UF_HOMEDIR_REQUIRED");
            comboBox1.Items.Add("UF_LOCKOUT");
            comboBox1.Items.Add("UF_PASSWD_NOTREQD");
            comboBox1.Items.Add("UF_PASSWD_CANT_CHANGE");
            comboBox1.Items.Add("UF_ACCOUNT_LOCKOUT");
            comboBox1.Items.Add("UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED");

        }

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

        private void button2_Click(object sender, EventArgs e)
        {
            // remove
            if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("Username: mandatory field", "Warning", MessageBoxButtons.OK);
                textBox1.Focus();
            }
            else if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Option flag: mandatory field", "Warning", MessageBoxButtons.OK);
                comboBox1.Focus();
            }
            else
            {
                UserManager um = new UserManager();
                if (!um.RemoveOptionFlagToUser(textBox1.Text, Convert.ToInt32(list[comboBox1.SelectedItem.ToString()].ToString())))
                    MessageBox.Show(um.ErrorMessage, "Warning", MessageBoxButtons.OK);
                else
                    MessageBox.Show("Option " + comboBox1.SelectedItem.ToString() + " removed.", "Warning", MessageBoxButtons.OK);

                um = null;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // add
            if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("Username: mandatory field", "Warning", MessageBoxButtons.OK);
                textBox1.Focus();
            }
            else if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Option flag: mandatory field", "Warning", MessageBoxButtons.OK);
                comboBox1.Focus();
            }
            else
            {
                UserManager um = new UserManager();
                if (!um.AddOptionFlagToUser(textBox1.Text, Convert.ToInt32(list[comboBox1.SelectedItem.ToString()].ToString())))
                    MessageBox.Show(um.ErrorMessage, "Warning", MessageBoxButtons.OK);
                else
                    MessageBox.Show("Option " + comboBox1.SelectedItem.ToString() + " added.", "Warning", MessageBoxButtons.OK);
                um = null;
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }
    }
}

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)

About the Author

Massimo Beatini
Web Developer
Italy Italy
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 2 Aug 2006
Article Copyright 2006 by Massimo Beatini
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid