Delete a User in NT

Question:
How do I delete a user in NT with the API’s?

Answer:
The code below shows how to delete a user (if the server name is blank, it attempts to delete a user on the local computer):

Option ExplicitPrivate Const NERR_Success As Long = 0&Private Declare Function NetUserDel _   Lib "Netapi32.dll" _   (Server As Any, _    UserName As Byte) As LongPublic Sub Main()   DelUser "\Herbert", "bbbb"   'DelUser "", "bbbb"End SubPublic Sub DelUser(ByVal xi_strServer As String, _                   ByVal xi_strUserName As String)   Dim p_abytServer() As Byte   Dim p_abytUser() As Byte   Dim p_lngRtn As Long      If Len(Trim$(xi_strServer)) <> 0 Then      p_abytServer = xi_strServer   End If      If Len(Trim$(xi_strUserName)) = 0 Then      MsgBox "You must supply a user name!"      Exit Sub   Else      p_abytUser = xi_strUserName & Chr$(0)            If Len(Trim$(xi_strServer)) = 0 Then         p_lngRtn = _            NetUserDel(Server:=ByVal Chr$(0), _            UserName:=p_abytUser(0))      Else         p_lngRtn =             NetUserDel(Server:=p_abytServer(0), _            UserName:=p_abytUser(0))      End If            If p_lngRtn = NERR_Success Then         MsgBox "Success"      Else         MsgBox "Could not delete the user, " & _                xi_strUserName & vbCrLf & _                "Error was: " & p_lngRtn      End If   End IfEnd Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS