Active Directory User Scanner is a C++ application that scans all computers in a Windows domain and collects logged-on users. The output is saved in a CSV file compatible with Excel. The tool supports multithreading for faster scanning in large environments.
- Scan all computers in an Active Directory domain
- List logged-on users for each computer
- Save results as UTF-8 BOM CSV (Excel compatible)
- Multithreading support for faster processing
- Registry-based SID-to-username resolution
- Error handling and reporting
- Windows operating system
- Visual Studio 2022
- Windows SDK
wldap32.lib(for LDAP operations)
| File | Description |
|---|---|
main.cpp |
Entry point of the program. Handles command-line arguments and starts the AD scanning process. |
ADHelper.h/.cpp |
Helper class for simplifying Active Directory operations, including fetching computers and users. |
LDAPQuery.h/.cpp |
Low-level LDAP query class. Manages LDAP connection, bind, and search operations. |
ReportGenerator.h/.cpp |
Responsible for generating the CSV report, writing data, and tracking statistics. |
- Download the project to your computer.
- Extract the Project to a Folder.
- Download Visual Studio to your computer
- Open the solution file (.sln).
- Select Build Solution from the Build menu.
Run the program from the command line:
program.exe -d <domain> -dc <domain_controller> -o <output_file> [options]-d, --domain→ Domain name (e.g.,example.com)-dc, --dc→ Domain Controller address (e.g.,dc.example.com)-o, --output→ Output CSV file (e.g.,report.csv)
-t, --threads→ Number of threads (default: 100, maximum: 500)-h, --help→ Show help message
program.exe -d example.com -dc dc.example.com -o report.csv -t 50Purpose: Writes scanning results to a CSV file and keeps statistics.
Key Functions:
Initialize()→ Creates the CSV file and writes the header rowAddEntry(const ComputerInfo&, const std::vector<UserInfo>&)→ Adds computer and user information (thread-safe)Close()→ Closes the CSV file and prints a summaryGetTotalComputers(),GetComputersWithUsers(),GetTotalUsers()→ Retrieve statistics
Helper Functions:
WStringToUTF8→ Convertsstd::wstringto UTF-8std::stringEscapeCSV→ Escapes commas, quotes, and newlines for CSV compatibility
Purpose: Handles low-level LDAP operations using Windows LDAP API.
Key Functions:
Initialize()→ Initialize LDAP connectionBind()→ Perform LDAP bind using negotiated authenticationSearch(baseDN, filter, attributes)→ Execute an LDAP searchGetAttributeValues(attributeName)→ Retrieve values for a specific attributeGetLastError()→ Retrieve the last LDAP error
Purpose: Simplifies LDAP queries and Active Directory operations.
Key Functions:
GetAllComputers()→ Retrieve all computers in the domainGetComputerOS(computerName)→ Retrieve the operating system of a computerGetLoggedOnUsers(fqdn)→ Retrieve users logged in on a specific computerDomainToDN(domain)→ Convert a domain name to LDAP DN formatExtractComputerName(fqdn, domain)→ Extract the computer name from its FQDN
- Parse command-line arguments (
ParseArguments) - Initialize
ADHelperandReportGenerator - Retrieve all computers from Active Directory (
GetAllComputers) - Divide computers among threads for multithreaded scanning (
ProcessComputerBatch) - Add logged-on users to CSV file
- Print a summary when scanning is complete
Computer,OS,SID,Logon User
PC1,Windows 10,,
PC2,Windows Server 2019,S-1-5-21-1234567890-1234567890-1234567890-1001,"DOMAIN\User1"
PC2,Windows Server 2019,S-1-5-21-1234567890-1234567890-1234567890-1002,"DOMAIN\User2"- Computers without users only display computer info
- Each user gets a separate row
- Uses
std::asyncandstd::future - Computer list is divided across threads
- Each thread processes a batch of computers
ReportGenerator::AddEntryensures thread-safe writes to CSV
- LDAP and registry errors are logged
- Inaccessible computers are skipped silently
- Error messages are written to
std::wcerr
This project is licensed under the MIT License. For more information, see the LICENSE file.