Results 1 to 11 of 11

Thread: How to create windows user using VB.NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    167

    How to create windows user using VB.NET

    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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to create windows user using VB.NET

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to create windows user using VB.NET

    To create a user you'd use ADSI. WMI is for hardware related methods, isn't it?

    VB Code:
    1. Public Sub AddUser(ByVal strDomainName As String, ByVal strLoginName As String, ByVal strPwd As String)
    2.  Dim obDirEntry As DirectoryEntry = Nothing
    3.  Try
    4.    obDirEntry = New DirectoryEntry("WinNT://" + strDomainName)
    5.    Dim entries As DirectoryEntries = obDirEntry.Children
    6.    Dim obUser As DirectoryEntry = entries.Add(strLoginName, "User")
    7.    obUser.Properties("FullName").Add("MENDHAK THE FROG")
    8.    Dim obRet As Object = obUser.Invoke("SetPassword", strPwd)
    9.    obUser.CommitChanges
    10.  Catch ex As Exception
    11.    'Handle the Error
    12.  End Try
    13. End Sub

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to create windows user using VB.NET

    WMI is not just for hardware.
    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.
    The Win32_UserAccount WMI class contains information about a user account on a Windows operating system.
    Can you use ActiveDirectory on a stand alone machine?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to create windows user using VB.NET

    Only if its got the ADSI type library or running Server w/AD.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to create windows user using VB.NET

    Here is a good link on ADSI for your reference.

    http://msdn.microsoft.com/library/de...oryobjects.asp
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Question Re: How to create windows user using VB.NET

    Quote Originally Posted by mendhak
    ...
    obDirEntry = New DirectoryEntry("WinNT://" + strDomainName)
    Dim entries As DirectoryEntries = obDirEntry.Children
    Dim obUser As DirectoryEntry = entries.Add(strLoginName, "User")
    Imports What? I tried Microsoft.win32, etc, never work though!
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: How to create windows user using VB.NET

    Quote Originally Posted by Codehammer
    Imports What? I tried Microsoft.win32, etc, never work though!
    http://www.google.com/search?client=...utf-8&oe=utf-8

    First link, form the MSDN says it's in the System.DirectoryServices namespace.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to create windows user using VB.NET

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to create windows user using VB.NET

    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?

  11. #11
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Lightbulb Re: How to create windows user using VB.NET

    Quote Originally Posted by mendhak
    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!
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width