By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Creating Local User with Web Service

P: n/a
Hi I am very new to .NET and I am programmatically trying to create a windows
users (not using AD) and am having a little trouble. The OS is 2003 Server
and I am trying to use System.Diagnostics.Process with "net.exe". The
argument does not seem to take, here is the code (this is my first crack at
web services or any real .net project so not sure if this the best way to do
this either - also please do not bash my code again it is my first try):

[WebMethod(Description = "Create Windows User and Custom Group.")]
public string CreateLocalUser(string username, string password)
{
Process MyProc = new Process();
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;

try
{
//this is the part that does not work
MyProc.StartInfo.Arguments = @"net.exe user " + username + @" " + password
+ @" /ADD /ACTIVE:YES " +@"/EXPIRES:NEVER /FULLNAME:" + username + @"
/PASSWORDCHG:NO /PASSWORDREQ:YES";
//

MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
catch(Exception e)
{
Console.WriteLine(e.GetType());
Console.WriteLine(e.Message);
}

return "completed";
}
Mar 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
q
Nice job so far... but please make your variables camelCased. It was
rather confusing reading that. I thought you were using static classes
for a minute...

Process MyProc = new Process();

should be

Process myProc = new Process();

Properties, types (i.e. classes), and methods should be PascalCased.

As far as your problem...

If you're doing AD stuff see this video:
http://channel9.msdn.com/Showpost.aspx?postid=132400

Otherwise, your arguments do look rather odd. Try removing the net.exe
from your arguments...

Mar 24 '06 #2

P: n/a
Okay I saw that I had net.exe twice but here is the new code:

Process myProcess = new Process();
myProcess3 = Process.Start("C:\\WINDOWS\\system32\\Net.exe", "user " +
username + " " + password + " /ADD /ACTIVE:YES " + "/EXPIRES:NEVER
/FULLNAME:" + username + " /PASSWORDCHG:NO /PASSWORDREQ:YES");

myProcess.WaitForExit();
myProcess.Close();

It throws no errors but does nothing, how can I make it so I can see what is
happening in the process to debug? Thanks for any help.

"Shannon Thompson" wrote:
Hi I am very new to .NET and I am programmatically trying to create a windows
users (not using AD) and am having a little trouble. The OS is 2003 Server
and I am trying to use System.Diagnostics.Process with "net.exe". The
argument does not seem to take, here is the code (this is my first crack at
web services or any real .net project so not sure if this the best way to do
this either - also please do not bash my code again it is my first try):

[WebMethod(Description = "Create Windows User and Custom Group.")]
public string CreateLocalUser(string username, string password)
{
Process MyProc = new Process();
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;

try
{
//this is the part that does not work
MyProc.StartInfo.Arguments = @"net.exe user " + username + @" " + password
+ @" /ADD /ACTIVE:YES " +@"/EXPIRES:NEVER /FULLNAME:" + username + @"
/PASSWORDCHG:NO /PASSWORDREQ:YES";
//

MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
catch(Exception e)
{
Console.WriteLine(e.GetType());
Console.WriteLine(e.Message);
}

return "completed";
}

Mar 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.