c#


ActiveDirectory Local Machine Account management - C#


I posted a question re LDAP account management, but after exploring this, it's not what i'm after. I've managed to find two ways of creating users on a machine, and i find one is much neater than the other, however, i am uncertain how to convert the first option over to the second option entirely.
This was my first solution:
Process MyProc = new Process();
MyProc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory;
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProc.StartInfo.Arguments = string.Format(#" user {0} {1} /ADD /ACTIVE:YES /EXPIRES:NEVER /FULLNAME:{0}"" /PASSWORDCHG:NO /PASSWORDREQ:YES", username, password);
MyProc.Start();
MyProc.WaitForExit();
int exit = MyProc.ExitCode;
MyProc.Close();
return exit == 0;
And this was my second (preffered) solution:
DirectoryEntry root = GetDELocalRoot();
DirectoryEntry user = root.Children.Add(username, "user");
//TODO: Always Active
//TODO: Never Expires
//TODO: No Password Change
//TODO: Password Required
user.Properties["description"].Value = "Account for running the MicaService and handling updates.";
user.Invoke("SetPassword", new object[] { password });
user.CommitChanges();
user.Close();
I would like to map all the settings in my TODO: from the first solution into my second neater solution.
I have tried the following line as well:
user.Properties["userAccountControl"].Value = ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT | ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE | ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;
But this does not work as the property does not exist in cache.
NOTE: the GetDELocalRoot() = return new DirectoryEntry("WinNT://" + Environment.MachineName);
Thanks for any input!
Regards
Tris
Check out my friend Richard Mueller's web site which has lots of useful information and reference material on what those two providers - WinNT for local machine accounts vs. LDAP for network accounts - have to offer.
There's also a Excel sheeet with all attributes that the WinNT provider exposes - it's a lot less than what the LDAP provider has, so I'm not sure if you'll be able to set all the properties you're looking for.
Marc

Related Links

Get element of an enum by sending XmlEnumAttribute c#?
I keep getting this error in while using ASP.NET Core
Wait for process to show up
Change Proxy at runtime in Selenium.Webdriver + PhantomJS using C#
Microsoft Dynamics Nav Post using Web Services
How do I modify my web.config file to support SQL Server 2016?
Web Api project with another data project both have entity framework only wanting connection string in data project
Use existing grid columns in a telerik radgridview as a class to add new rows
Rider IDE and .net Core install not found
Generar Scripts para trasladar datos
How do I pass a model from controller to another controller in asp .net core?
Could not install package 'System.Security.SecureString'
How to do REST API Optional string URI parameter with Azure Function HTTP Binding?
Consuming class libraries built using .NET Core
Smooth camera follow stutter
ToInt32 throwing weird results [duplicate]

Categories

HOME
pact
sip
oracle-sqldeveloper
postgresql-9.3
display
latex
liquibase
ubuntu-14.04
xss
ebay
uml-designer
opacity
python-3.4
sahi
facebook-sharer
vichuploaderbundle
point-of-sale
expo
beacon
bootstrap-datetimepicker
formulas
klipfolio
infinite-loop
prepros
knapsack-problem
pydub
ocl
ibm-bpm
wercker
ports
node-soap
rtos
jsonapi-resources
android-geofence
scip
console.readline
const
pygraphviz
latency
linkurious
aspose.pdf
julia-jump
socketcluster
amazon-rds-aurora
android-doze-and-standby
qtwebkit
hierarchical-clustering
node-java
msiexec
esprima
stringbuilder
android-music-player
firebase-job-dispatcher
netlink
normalisation
bytearray
system-integration
audiorecord
boost-propertytree
bbedit
nslocalizedstring
play-json
transbase
teamwork
avd
numerical-recipes
sony-xperia
shunting-yard
cordova-3
worklight-appcenter
switchpreference
farpoint-spread
pidgin
imaplib
jfilechooser
proj4
junction-table
mysql2
nx
rfc822
certificate-revocation
aspmenu-control
mysql-connector
jqueryi-ui-buttonset
stl-algorithm
log-shipping
soapexception
qvariant
javah
azure-appfabric
datarelation
google-local-search
mysql-pconnect
opengl-to-opengles
cross-cutting-concerns

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App