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

Create windows user account

P: n/a
Hi,

how can I create a new windows user account in VB.Net code and add it to the
admin or power user group?

Thanks in advance.
--
Best regards

Henry
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi

I think we can use the code as below to do the job.
The sample below will create a user account UserID and then add it into the
administators group in the computername

Module Module1
Sub Main()
'Create Account
On Error Resume Next
Dim strUser As String = "UserID"
Dim oDomain As Object = GetObject("WinNT://computername")
Dim oUser As Object = oDomain.Create("user", strUser)
If (Err.Number = 0) Then
oUser.SetInfo()
oUser.SetPassword("Password")
oUser.SetInfo()
End If

'Add to addministrators
strUser = "UserID"
Dim strGroup As String = "Administrators"
oDomain = GetObject("WinNT://computername")
Dim oGroup As Object = oDomain.GetObject("Group", strGroup)
oGroup.Add("WinNT://computername/" & strUser)
End Sub
End Module

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.