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

Set Background of Particular DataGrid Cell
what is the error in this code datagridview?
Winforms - what is the simplest way to update a property in thread safe manner
Keyboard on the screen in WinForms
strange error messages in web.config?
treat Enum as generic?
Editing an entity's related collection when editing the entity
Dynamic Code - C#
disposing generic list of bitmapimages
Printer properties Dialog Saved changes
Using SharpFFmpeg.dll for video conversion
How to Add dynamic control instead of static control?
HttpRequest giving parameter to AsyncCallback delegate
Handling autocompletion in text boxes. differently from pressing enter
Dataset.WriteXml() namespace and prefix
Add Image Column to a GridView After Binding

Categories

HOME
qlikview
twitter-bootstrap
netty
python-requests
ubuntu-14.04
overrides
markdown
clip-path
google-api-oauth
webpack-dev-server
phpexcel
kairosdb
browsermob
webseal
jsfiddle
url-parameters
waterfall
datastax-enterprise
rancher
paper-trail-gem
jboss-arquillian
textview
opencsv
blockly
webclient
fastadapter
matlab-compiler
mootools
pyenv
javafxports
matrix-multiplication
scalamock
file-descriptor
quartz
mtm
cakephp-3.2
text-formatting
easyquery
jsfl
openidm
intermediate-language
richtext
android-vectordrawable
webmatrix
senti-wordnet
toggleclass
easy68k
strtol
jira-agile
netlink
aws-kms
3d-rendering
containstable
bluetooth-lowenergy-4.2
android-contentresolver
gulp-cdnizer
cyberduck
playn
page-refresh
tinymce-plugins
pymol
shunting-yard
grunt-contrib-connect
nsmutableurlrequest
sat4j
parallel-port
nativequery
ekevent
xcode6.1-gm-seed
google-mirror-api
grunt-contrib-imagemin
friendly-id
android-library
proj4
http-compression
msbuild-task
simplemembership
auctex
system.transactions
nsregularexpression
m3u
event-propagation
wxperl
visual-leak-detector
yii-cactiverecord
jqzoom
zend-validate
gmagick
nbehave
cryptolicensing
http-response-codes
oaw
pitch-shifting
mysql-logic
file-icons

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