How can I create a machine account ?


  • I wanted to create a machine account and should be able to all the modification and play with it...i am using C#.

    If anyone can give me some would be really nice...thanks.



    Tuesday, June 06, 2006 8:44 PM

All replies

  • Using the Windows net command, it’s easy to create local Windows User Accounts. The syntax for the net command is:

    net user [username] [password] /ADD

    The following C# function takes in three parameters -- username, password and home directory.

    using System.Diagnostics;
    public void CreateLocalUser(string username, string password, string homedir)
      if (!Directory.Exists(homedir))
      Process MyProc = new Process();
      MyProc.StartInfo.WorkingDirectory = "C:\WINNT\SYSTEM32";
      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 = @" user " + username + @" " + password + @" /ADD /ACTIVE:YES " +
        @"/EXPIRES:NEVER /FULLNAME:" + username + @" /HOMEDIR:""" + 
        homedir + @""" /PASSWORDCHG:NO /PASSWORDREQ:YES";

    this code snippet is got from here

    hope it helps

    Tuesday, June 06, 2006 8:49 PM
  • Hello  Galin Iliev,

    Thank you. what about if I wanted to create a machine account to the NT server so where ppl can create a machine account with the specific domain. I am working on the school project and i am learning .Net. It will be really helpful if you give me some more feed back or some links where I can get some more information.

    thank you again,



    Wednesday, June 07, 2006 1:17 PM
  • I highly suggest looking into the Network Management Functions

    you will have to use P/Invoke to call them, but I found taht they work better for creating local accounts then ADSI, in fact we ran into a bug here where trying to search for a group on a local machine was causiing a 30 sec delay while the program tried to access an AD server taht wasn't there and we were using the WINNT bindings.
    Thursday, June 08, 2006 2:53 PM
  • Thanks CalvinR

    I will have a look at it. Basically i wanted to create a machine account in the active directory in windows 2003 server. will see....thanks


    Thursday, June 08, 2006 4:35 PM