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

Uploading a PDF file from Fiddler to a WebAPI method results in 415 Unsupported Media Type
How to specify subclass types in JSON (in a REST web service)
UniVerse records containing special characters skewing output
How do I manage remote WebFarms using c#?
How to request a simplified(reduced) version of a webpage from a web server
Why does my streamreader and writer suddenly stop working?
I'm getting 403 with HttpClient on Portable Class Library
Does the DockingManager come with a built-in method for handling Anchorables
how to add html into a modelstate
Errors/Problems using Xdocument.Parse
Large sized string by ref or value?
Using Zip to combine 3 strings instead of 2
nHiberanate 3.0 + Fluent nHiberanate : “No Persister for:” Error
Search string from text file and display selected line
Implementing custom return value in Authentication Service
Is there any equivalent of Type.IsInterface or IsClass in Windows Store .NET?

Categories

HOME
oauth-2.0
logging
indexing
teradata
network-programming
oracle-sqldeveloper
service
customization
weblogic
dronekit
latex
postsharp
arcgis
magento-1.9.2.1
ubuntu-14.04
bitbucket
xss
css-selectors
glympse
kohana
qt4
annyang
google-my-business-api
apache-httpclient-4.x
decoding
yui
box2d
greensock
powerpivot
google-street-view
udeploy
spring-webflow
url-parameters
formulas
connectiq
ng-tags-input
rancher
mongoose-im
pydub
edsdk
boost-log
multilanguage
imdb
circle
webspeech-api
gstreamer-1.0
linkurious
collation
aspnetboilerplate
compiler-warnings
definition
taiga
weld
history
ear
node-java
hellosign
liferay-ide
jtextarea
petapoco
node.js-client
google-scholar
portaudio
firebase-polymer
racket-student-languages
mac-app-store
symantec
jira-agile
rowname
diameter-protocol
django-celery
supervised-learning
transaction-isolation
nd4j
sqlxml
stdlist
dcast
askbot
matlab-engine
jcomponent
log4cxx
pushwoosh
syncano
azure-mobile-app
litedb
transparentproxy
httpmodule
ultraedit
bungeecord
beagleboard
strcpy
nexusdb
dockerpy
chunks
nsq
crtdbg.h
illegalargumentexception
disabled-control
amzi-prolog
behance-api
xpand
ant-contrib
traceur
cvi
ftpwebrequest
tasklist
beep
systrace
pdf-reader
mvcmailer
nsundomanager
openwrap
execjs
jexcelapi
hwnd
lwp
fxcopcmd
database-agnostic
newspeak
uccapi
retrospectiva
authkit
cstring
stackless

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