A Rust crate for managing local Windows users and groups using the Windows API in Rust.
Features
- Create, update, delete, and fetch local users
- Create, update, delete, and query local groups
- Add or remove users from local groups
- Support for local and remote machine management
- Well-known SID helpers (
Users,Administrators, etc.) - User enumeration with
UserFilterFlags
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage Examples
Create a manager
use UserManager;
// Local machine
let mgr = local;
// Remote machine
let mgr = remote;
Creating a User and Assigning a Group
On Windows, creating a local user account is often not enough by itself.
A user should usually be added to a local group so Windows can determine which permissions and capabilities the account has.
The most common groups are:
- Users → standard account with basic access to the machine
- Administrators → elevated account with full system privileges
In most applications, adding the account to the Users group is the recommended and safest default.
use ;
let mgr = local;
let username = "DemoUser1";
// Create the user
let user = builder
.name
.password
.full_name
.comment
.build;
match mgr.add_user
// Add the user to the standard Users group
let users_group = USERS.name.unwrap;
match mgr.add_users_to_group
// Delete the user
match mgr.delete_user
Creating and Managing a User
use ;
let mgr = local;
let username = "DemoUser2";
// Create a new user
let user = builder
.name
.password
.full_name
.comment
.build;
// Add the user
match mgr.add_user
// Verify the user exists
match mgr.user_exists
let settings = builder
.comment
.full_name
.build;
// Update the user
match mgr.update_user
// Delete the user
match mgr.delete_user
Using Struct Methods
use ;
let mgr = local;
// Create a new user
let mut user = builder
.name
.password
.build;
// Add the user
match user.add
// Verify the user exists
match user.exists ;
let update = builder
.comment
.build;
// Update the user
match user.update
// Delete the user
match user.delete
Managing Group Membership
use ;
let mgr = local;
let username = ;
let group_name = USERS.name.unwrap;
match mgr.add_users_to_group
match mgr.list_group_members
match mgr.remove_users_from_group
Listing Local Users
use ;
let mgr = local;
match mgr.count_users
match mgr.list_users
Requirements
- Windows 7 or later
- Administrative privileges for certain operations
Support
For issues and questions:
- Open an issue on GitHub
- Check the documentation
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.