I have a table in sql server storing all staff in a company and I want to create user in windows for all staff. I don't want to create it one by one. Can i use vb.net to create theses users or is there any way? Please tell me step by step.
Printable View
I have a table in sql server storing all staff in a company and I want to create user in windows for all staff. I don't want to create it one by one. Can i use vb.net to create theses users or is there any way? Please tell me step by step.
You will want to use Active Directory (AD) or Windows Management Instrumentation (WMI) to do it. You are trying to create local users or domain users, etc.
To create a user you'd use ADSI. WMI is for hardware related methods, isn't it?
VB Code:
Public Sub AddUser(ByVal strDomainName As String, ByVal strLoginName As String, ByVal strPwd As String) Dim obDirEntry As DirectoryEntry = Nothing Try obDirEntry = New DirectoryEntry("WinNT://" + strDomainName) Dim entries As DirectoryEntries = obDirEntry.Children Dim obUser As DirectoryEntry = entries.Add(strLoginName, "User") obUser.Properties("FullName").Add("MENDHAK THE FROG") Dim obRet As Object = obUser.Invoke("SetPassword", strPwd) obUser.CommitChanges Catch ex As Exception 'Handle the Error End Try End Sub
WMI is not just for hardware.Quote:
The Win32_Account abstract WMI class contains information about user accounts and group accounts known to the Windows system. User or group names recognized by a Windows NT domain are descendants (or members) of this class. The Win32_Account class is not included in a default hardware inventory operation.
Can you use ActiveDirectory on a stand alone machine?Quote:
The Win32_UserAccount WMI class contains information about a user account on a Windows operating system.
Only if its got the ADSI type library or running Server w/AD.
Here is a good link on ADSI for your reference.
http://msdn.microsoft.com/library/de...oryobjects.asp
Imports What? I tried Microsoft.win32, etc, never work though!Quote:
Originally Posted by mendhak
http://www.google.com/search?client=...utf-8&oe=utf-8Quote:
Originally Posted by Codehammer
First link, form the MSDN says it's in the System.DirectoryServices namespace.
I went to the help/MSDN library and searched for "directoryentry class". The third result was for the System.DirectoryServices.DirectoryEntry class. The help really is helpful. The page that Rob linked to even has a link to that very topic and half the other links specifically mention the DirectoryServices namespace.
It's surprising how much a little, tiny search can answer if you just take the time out to do it. That was an extremely simple question, ya see?
My Last Imports Question Ever Again!Quote:
Originally Posted by mendhak