Erm's I.T. Girl – Zelna Ellis

Don't fear when Zel is near…

VB.NET Add Local User and Group Accounts with Net Command

It can be quite a mission if you need to add a local user and/or group without AD (Active Directory) in VB.NET. There are other ways, e.g. Scripting etc., but this is really easy. The downfall here is that you won’t see any error messages but you can always use WMI to see if a group and/or user exists. The normal rules for the net.exe command count and you can use the parameters you need.

proc.StartInfo.Arguments = "enter the parameters for the command here"
If you do know of a more efficient way to do it, please share it with us.

Note: Usually one will get the username, password, group, etc. from the GUI’s textboxes. Left it out in this example to simplify the code.

Download code (PDF) here.

Imports System
Imports System.Diagnostics

Public Class CheckUser02

     Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
               Dim proc As New Process
               proc.StartInfo.FileName = "net.exe"
               proc.StartInfo.UseShellExecute = False
               proc.StartInfo.CreateNoWindow = True 'Don’t show command prompt window.

               'Add localgroup named "test" with "The Test Group" as a comment(Description of Group)
               proc.StartInfo.Arguments = "localgroup test /ADD /COMMENT:Test-Group"
               'Add local user names "test1" where the user password = "12345"
               proc.StartInfo.Arguments = "user test1 12345 /ADD /FULLNAME:TestUser1"
               'Add local user "test1" to localgroup "test1"
               proc.StartInfo.Arguments = "localgroup test test1 /ADD"

          Catch ex As Exception
          End Try
     End Sub
End Class


29 September 2009 - Posted by | .NET & MySQL | , , , , , , , ,


  1. I don’t know If I said it already but …Hey good stuff…keep up the good work! 🙂 I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks,)

    A definite great read..Jim Bean

    Comment by JimmyBean | 1 October 2009 | Reply

    • Thank You Jim,
      Glad you enoyed your visit here 🙂
      Due to exams I’ll be back in November 😦

      Comment by zellis | 2 October 2009 | Reply

  2. Read this post if you want to get error messages from the net command, if any:

    Comment by zellis | 17 October 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: