Win NT Domain Management from VB5

Win NT Domain Management from VB5

Question:
Are simple domain management tasks such as “Add User to a Group” or “Add a Computer to an NT domain” possible under VB5? Do you have sample codes?

Answer:
Adding a user to a global group is not very difficult. The code below will allow you to do this. Note that you should replace “\LJ_Server” with the name of your PDC, “TestGroup” with the name of an already-created global group, and “xxx” with the name of a user already entered in on the PDC.

I was not able to find a way to add a computer to the NT domain. Apparently, that function is not exposed via the 32-bit API, which kinda makes sense, security-wise, but is rather annoying nonetheless.

Private Sub Command1_Click()  AddUserToGlobalGroup "\LJ_Server", _                       "TestGroup", _                       "xxx"End SubOption ExplicitDeclare Function NetGroupAddUser _   Lib "netapi32.dll" _   (ServerName As Byte, _    GroupName As Byte, _    UserName As Byte) As LongPrivate Const NERR_Success          As Long = 0&Private Const NERR_Base             As Long = 2100Private Const NERR_InvalidComputer  As Long = NERR_Base + 251Private Const NERR_NotPrimary       As Long = NERR_Base + 126Private Const NERR_GroupExists      As Long = NERR_Base + 123Private Const NERR_UserNotFound     As Long = NERR_Base + 121Private Const NERR_GroupNotFound    As Long = NERR_Base + 120Private Const NERR_UserNotInGroup   As Long = NERR_Base + 137' ------------------------------' Add a user to the global group' ------------------------------Public Sub AddUserToGlobalGroup(ByVal xi_strServerName As String, _               ByVal xi_strGroupName As String, _               ByVal xi_strUserName As String)   Dim p_abytServerName()  As Byte   Dim p_abytGroupName()   As Byte   Dim p_abytUserName()    As Byte   Dim p_lngRtn            As Long   Dim p_strErr            As String      ' ------------------------------   ' Convert strings to byte arrays   ' ------------------------------   p_abytServerName = xi_strServerName & vbNullChar   p_abytGroupName = xi_strGroupName & vbNullChar   p_abytUserName = xi_strUserName & vbNullChar     ' ------------------------------   ' Make the call to add user   ' ------------------------------   p_lngRtn = NetGroupAddUser(p_abytServerName(0), _                              p_abytGroupName(0), _                              p_abytUserName(0))         If p_lngRtn <> NERR_Success Then      ' Need to raise an error      p_strErr = "Failed to add the user '" & _                 xi_strUserName & _                 "' to the global group, '" & _                 xi_strGroupName & "'"            Select Case p_lngRtn         Case NERR_InvalidComputer            p_strErr = p_strErr & " -- This server name is invalid: '" & _                       xi_strServerName & "'."         Case NERR_NotPrimary            p_strErr = p_strErr & " -- This operation is only allowed on the primary domain controller of the domain."         Case NERR_GroupExists            p_strErr = p_strErr & " -- The group already exists."         Case NERR_UserNotFound            p_strErr = p_strErr & " -- The user name could not be found."         Case NERR_GroupNotFound            p_strErr = p_strErr & " -- The group name could not be found."         Case NERR_UserNotInGroup            p_strErr = p_strErr & " -- The user does not belong to this group."         Case 53            p_strErr = p_strErr & " -- The network path was not found."         Case Else            ' Just keep original error string            p_strErr = p_strErr & "."      End Select               Err.Raise Number:=p_lngRtn, _                Source:="AddUserToGlobalGroup", _                Description:=p_strErr   End If   End Sub
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing