all groups > dotnet web services > march 2006 >
You're in the

dotnet web services

group:

Creating Local User with Web Service


Creating Local User with Web Service Shannon Thompson
3/23/2006 11:54:02 PM
dotnet web services:
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";
}

Re: Creating Local User with Web Service q
3/24/2006 8:20:41 AM
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...
RE: Creating Local User with Web Service Shannon Thompson
3/24/2006 9:45:02 AM
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.

[quoted text, click to view]
AddThis Social Bookmark Button