George Waters


Hi all,

I'm trying to add users remotely to a Windows 2003 Standard using the command net.exe, but I just can't make it work. This is my code:

Dim p As New Process

p.StartInfo.UseShellExecute = False

p.StartInfo.RedirectStandardError = True

p.StartInfo.RedirectStandardInput = True

p.StartInfo.RedirectStandardOutput = True

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

p.StartInfo.Arguments = " user " & xUser & " " & xPass & " /ADD /ACTIVE:YES /EXPIRES:NEVER"

p.StartInfo.WorkingDirectory = "C:\windows\system32"

p.StartInfo.FileName = "net"

p.Start()

Dim sr As IO.StreamReader = p.StandardOutput

Dim sb As New System.Text.StringBuilder("")

Dim sinput As String = ""

Do Until sinput = "-1"

sb.Append(sr.ReadLine() & ControlChars.CrLf)

sinput = sr.Read

Loop

p.WaitForExit()

p.Close()

Return sb.ToString

it doesn't return anything, and user is not created.

If I change the following line, it returns perfectly the table of users:

p.StartInfo.Arguments = " users"

so what could the problem be

Thanks in advance.

George



Re: Create Users to Windows 2003 Programatically (vb)

Bruno Yu - MSFT


George Waters,

1. Please use "net.exe" instead of "net" since it is file name.

2. Dim xUser as String = "Username" Dim xPass as String = "Password".

3. The path of net.exe in Windows 2003 is in C:\WINNT\System32. Mine is X64, so the path of mine is C:\WINNT\syswow64\. Please pay more attention to the exact path for the file.

4. Run ¡°net user / ¡± at command line or check http://support.microsoft.com/kb/251394 for the document.

5. The more appropriate way to create a user account with VB.Net is to use ADSI

http://msdn2.microsoft.com/En-US/library/aa746340.aspx