Network Information/Modification Module (NIMM) Readme

Table of Contents

1) Overview

2) Features

3) Usage           <- ** A MUST READ **

4) Credits

5) Support




































Overview of the Network Information/Modification Module (NIMM)

   NIMM provides visual basic developers with a simple interface to advanced network information and modification operations. You can easily incorporate it into your existing Visual Basic applications.





Features of the Network Information/Modification Module (NIMM)

   NIMM has the ability to enumerate (list) network domains, global/local groups, users in a domain, users in a local/global group, and currently logged on users. You can add and remove users, local/global groups. Change user passwords, get user information, find the Primary Domain Controller (PDC) of a domain, and logon to a specified domain. All functions have been optimized for ease of use. Functions that enumerate return arrays, functions that change things return booleans (worked/didn't work). Functions that return information.... return information.





Usage of the Network Information/Modification Module (NIMM)

   Below is a listing of functions, a definition of what they do, the arguments they require, the variables returned and the operating systems they work on:

Alphabetical
AddNewUser
AddUserToGlobalGroup
AddUserToLocalGroup
ChangePassword
DelUser
DelUserFromGlobalGroup
DelUserFromLocalGroup
EnumDomains
EnumGlobalGroups
EnumLocalGroups
EnumUsers
EnumUsersInGlobalGroup
EnumUsersInLocalGroup
EnumUsersLoggedOn
GetPDCName
GetUserInfo
Login
SetServerComment
Catagorical
Global Groups
AddUserToGlobalGroup
DelUserFromGlobalGroup
EnumGlobalGroups
EnumUsersInGlobalGroup
 
Local Groups
AddUserToLocalGroup
DelUserFromLocalGroup
EnumLocalGroups
EnumUsersInLocalGroup
 
Users
AddNewUser
ChangePassword
DelUser
EnumGlobalGroups
EnumLocalGroups
EnumUsers
EnumUsersLoggedOn
GetUserInfo
 
Misc.
EnumDomains
GetPDCName
Login
SetServerComment



















Add New User
 
AddNewUser(Server, Username, Password, [FullName], [UserComment]) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies the server you want to create the user on. Usually the domains PDC.
   Username  StringThe desired username of the new user account account.
   Password  StringThe password that the new account will use.
Optional Arguments:
   FullName  StringOptional. If provided, the fullname specified here will be used for the user account.
   UserComment  StringOptional. If provided, the comment specified here will be used for the user account.
 
Returns:
   True  If returns true, the account was successfully created on the server.
   False  If returns false, the account was not created on the server. See notes.
 
Notes:
 Possible reasons this would fail: Insufficient permissions to create accounts, the specified username already exists, the password is shorter than the required length or you're using Windows 95/98.
 
Example:
Dim MyPDC As String
MyPDC = GetPDCName("MyDomainName")
If AddNewUser(MyPDC,"jdoe","John Doe","New anonymous user.") Then
  MsgBox "User account was created successfully"
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Add User To Global Group
 
AddUserToGlobalGroup(Server, Username, GlobalGroup) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies a PDC or BDC for the domain.
   Username  StringSpecifies the user that you wish to add to the group.
   GlobalGroup  StringSpecifies the global group that you wish to add the user to.
Optional Arguments:
 
Returns:
   True  If returns true, then the user was successfully added to the group.
   False  If returns false, the function was unable to add the user to the group. See notes.
 
Notes:
 Possible reasons this would fail: Insufficient permissions to add to global group, unable to access the server or you're using Windows 95/98.
 
Example:
Dim MyPDC As String
MyPDC = GetPDCName("MyDomain")
If AddUserToGlobalGroup(MyPDC,"jdoe","Administrators") Then
  MsgBox "Successfully added user to global group!"
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Add User To Local Group
 
AddUserToLocalGroup(Server, Username, LocalGroup) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies the computer contains the local group you wish to add the user to.
   Username  StringSpecifies the user that you wish to add to the group.
   LocalGroup  StringSpecifies the local group that you wish to add the user to.
Optional Arguments:
 
Returns:
   True  If returns true, then the user was successfully added to the group.
   False  If returns false, the function was unable to add the user to the group. See notes.
 
Notes:
 Possible reasons this would fail: Insufficient permissions to add the user to the local group, unable to access the server or you're using Windows 95/98.
 
Example:
AddUserToGlobalGroup("\\mycomputername","jdoe","Shared Access")
Compatability:
  Windows 95/98    Windows 2000/NT  



















Change User Password
 
ChangePassword(Domain, Username, OldPassword, NewPassword) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Domain  StringSpecifies the domain on which the specified user account resides.
   Username  StringSpecifies the username whose password you want to change.
   OldPassword  StringThe users current password. This can be left blank, if you have administrative permissions on the domain.
   NewPassword  StringThe password you wish to change it to.
Optional Arguments:
 
Returns:
   True  If returns true then the password was successfully changed.
   False  If false then the function was unable to change the password. See Notes.
 
Notes:
 Possible reasons this would fail: Insufficient permissions to change the password, unable to access the domain server or you're using Windows 95/98.
 
Example:
If ChangePassword("MyDomain","jdoe","mypassword","newpassword") Then
  MsgBox "Password Successfully Changed!"
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Delete User Account From Domain
 
DelUser(Server, Username) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies a PDC or BDC on the domain of the user account you wish to delete.
   Username  StringThe username of the account you wish to delete.
Optional Arguments:
 
Returns:
   True  The user account was successfully deleted.
   False  The function was unable to delete the account. See Notes.
 
Notes:
 Possible reasons this would fail: Insufficient permissions to delete the account, unable to access the server or you're using Windows 95/98.
 
Example:
Dim MyPDC As String

MyPDC = GetPDCName("MyDomain")

If MsgBox("Are you sure you want to delete the account?",vbYesNo)=vbYes Then
  If DelUser(MyPDC,"jdoe") Then
    MsgBox "The specified account has been deleted!"
  End If
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Remove User From Global Group
 
DelUserFromGlobalGroup(Server, Username, GlobalGroup) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Server  StringA PDC or BDC on the domain in which the user and group reside.
   Username  StringSpecifies the user that you wish to remove from the group.
   GlobalGroup  StringSpecifies the group that you wish to remove the user from.
Optional Arguments:
 
Returns:
   True  The user was successfully removed from the group.
   False  The function was unable to remove the user from the group. See Notes.
 
Notes:
 Possible reasons this would fail: The group does not exist, insufficient permissions to remove the user from the group, unable to access the server or you're using Windows 95/98.
 
Example:
Dim MyPDC As String

MyPDC = GetPDCName("MyDomain")
If DelUserFromGlobalGroup(MyPDC,"jdoe","Administrators") Then
  MsgBox "The user was successfully removed from the group."
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Remove User From Local Group
 
DelUserFromLocalGroup(Server, Username, LocalGroup) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies the computer on which the local group resides.
   Username  StringSpecifies the user that you would like to remove from the local group
   LocalGroup  StringSpecifies the local group to remove the user from.
Optional Arguments:
 
Returns:
   True  The user was successfully removed from the local group.
   False  The function was unable to remove the user from the local group. See Notes.
 
Notes:
 Possible reasons this would fail: The group does not exist, insufficient permissions to remove the user from the group, unable to access the server or you're using Windows 95/98.
 
Example:
If DelUserFromLocalGroup("\\mycomputername","jdoe","MyLocalGroup") Then
  MsgBox "The user was successfully removed from the group."
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Available Domains
 
EnumDomains() As Variant
 
Required Arguments:
 
Optional Arguments:
 
Returns:
   Array of Strings  If successful, the function returns an array of accessible domains.
 
Notes:
 If the function is unsuccessful, an empty array will be returned.
 
Example:
Dim ADomain As Variant

For Each ADomain in EnumDomains()
  MsgBox "The following domain is accessible: " & ADomain
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Global Groups
 
EnumGlobalGroups(Server, [Username]) As Variant
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies a PDC or BDC of the domain.
Optional Arguments:
   Username  StringOptional. If a username is specified the function will enumerate all groups which that user is a member of.
 
Returns:
   Array of Strings  If successful, an array of global groups will be returned.
 
Notes:
 If unsuccesful, an error will be raised.
 
Example:
Dim MyPDC As String
Dim Group As Variant

MyPDC = GetPDCName("MyDomain")

For Each Group In EnumGlobalGroups(MyPDC)
  MsgBox "The following global group exists: " & Group
Next

For Each Group In EnumGlobalGroups(MyPDC,"jdoe")
  MsgBox "The user is a member of the following global group: " & Group
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Local Groups
 
EnumLocalGroups(Server, [Username]) As Variant
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies the computer to retrieve the local groups from..
Optional Arguments:
   Username  StringOptional. If a username is specified the function will enumerate all groups which that user is a member of.
 
Returns:
   Array of Strings  If successful, an array of local groups will be returned.
 
Notes:
 If unsuccesful, an error will be raised.
 
Example:
Dim Group As Variant

For Each Group In EnumLocalGroups("\\acomputername")
  MsgBox "The following local group exists on the computer: " & Group
Next

For Each Group In EnumLocalGroups("\\acomputername","jdoe")
  MsgBox "The user is a member of the following local group on the computer: " & Group
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Users On A Domain
 
EnumUsers(Server) As Variant
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies a PDC or BDC on the domain to retrieve the user accounts from.
Optional Arguments:
 
Returns:
   Array of Strings  If successful, an array of usernames is returned.
 
Notes:
 If unsuccessful, an error will be raised.
 
Example:
Dim MyPDC As String
Dim Username as String

MyPDC = GetPDCName("MyDomain")

For Each Username in EnumUsers(MyPDC)
  Debug.Print "The following users exists: " & Username
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Users In A Global Group
 
EnumUsersInGlobalGroup(Server, GlobalGroup) As Variant
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies a PDC or BDC on the domain.
   GlobalGroup  StringSpecifies the global group you wish to retrieve members from.
Optional Arguments:
 
Returns:
   Array of Strings  If successful, an array of usernames will be returned.
 
Notes:
 If unsuccessful, an error will be raised.
 
Example:
Dim MyPDC As String
Dim Username as String

MyPDC = GetPDCName("MyDomain")

For Each Username in EnumUsersInGlobalGroup(MyPDC,"Administrator")
  Debug.Print "The following user is a member of the global group: " & Username
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Users In A Local Group
 
EnumUsersInLocalGroup(Server, LocalGroup) As Variant
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies the computer on which the local group resides.
   LocalGroup  StringSpecifies the local group you wish to obtain a member list from.
Optional Arguments:
 
Returns:
   Array of Strings  If successful, an array of usernames will be returned.
 
Notes:
 If unsuccessful, an error will be raised.
 
Example:
Dim Username as String

For Each Username in EnumUsersInLocalGroup("\\acomputername","MyLocalGroup")
  Debug.Print "The following user is a member of the local group: " & Username
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Enumerate Users Currently Logged On
 
EnumUsersLoggedOn(Server) As Variant
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies a PDC or BDC of the domain you wish to retrieve the currently logged on users from.
Optional Arguments:
 
Returns:
   Array of Strings  If successful, returns an array of usernames of users that are currently logged onto the domain.
 
Notes:
 If unsuccessful, an error will be raised. This function might take a while (respective to the others) as it actually retrieves a list of all users on the domain, the gets each users "Last Logon Time" and "Last Logoff Time" and compares them.
 
Example:
Dim MyPDC As String
Dim LoggedOnUser As Variant

MyPDC = GetPDCName("MyDomain")

For Each LoggedOnUser In EnumUsersLoggedOn(MyPDC)
  MsgBox LoggedOnUser & " is currently logged onto the domain."
Next
Compatability:
  Windows 95/98    Windows 2000/NT  



















Get The Computername Of A Primary Domain Controller (PDC)
 
GetPDCName([Domain], [Server]) As String
 
Required Arguments:
 
Optional Arguments:
   Domain  StringSpecifies the domain to retrieve the PDCs computername from.
   Server  StringSpecifies the computer to retrieve the PDCs computername from.
 
Returns:
   String  If successful, a string containing the computername of the PDC is returned.
 
Notes:
 If unsuccessful, an error will be raised. You can specify a domain name or a server name or nothing, but do not try to specify both. If you specify a domain, the PDC for that domain will be returned. If you specify a server, the domain that the server is a member of will be returned. If neither a domain or server is specified, it will return the PDC of the domain that your computer is a member of.
 
Example:
Dim MyPDC As String
Dim AnotherPDC As String


MyPDC = GetPDCName()
AnotherPDC = GetPDCName("AnotherDomain")
AnotherPDC = GetPDCName( ,"\\somecomputer")
Compatability:
  Windows 95/98    Windows 2000/NT  



















Get User Information
 
GetUserInfo(Server, Username) As USER_INFO
 
Required Arguments:
NameVariable TypeDescription
   Server  StringSpecifies the PDC or BDC to retrieve the users information from.
   Username  StringSpecifies the username to obtain the information from.
Optional Arguments:
 
Returns:
   USER_INFO  If successful, the users information will be returned using the USER_INFO structure.
 
Notes:
 If unsuccessful, an error will be raised. Review the USER_INFO structure.
 
Example:
Dim MyPDC As String
Dim UsersInfo As USER_INFO
MyPDC = GetPDCName("MyDomain")

UsersInfo = GetUserInfo(MyPDC, "jdoe")

MsgBox "This information is about " & UsersInfo.Name
MsgBox "Users full name is: " & UsersInfo.Fullname
MsgBox "The comment in the account is: " & UsersInfo.Comment
MsgBox "The comment about the user is: " & UsersInfo.UserComment
Compatability:
  Windows 95/98    Windows 2000/NT  



















Logon To A Domain
 
Login(Username, Password) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Username  StringSpecifies the username to use to logon to the domain with.
   Password  StringSpecifies the password to use to logon to the domain with.
Optional Arguments:
 
Returns:
   True  Returns true if it successfully logged your computer onto the domain.
   False  Returns false if it was unable to logon to the domain.
 
Notes:
 The domain used to log onto is the default domain specified in your computers network settings. Possible failure reasons: Just about anything! (User account expired, not within user logon hours, incorrect password, non existant username, unable to reach a domain controller, etc...)
 
Example:
If Login("jdoe","mypass") Then
  MsgBox "You have been successfully logged onto the domain.
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















Set The Comment For A Computer
 
SetServerComment(Comment,[Server]) As Boolean
 
Required Arguments:
NameVariable TypeDescription
   Comment  StringSpecifies the comment to use.
Optional Arguments:
   Server  StringOptional. Specifies the computer whose comment you wish to change. If left blank, your computer will be used.
 
Returns:
   True  Comment was successfully changed.
   False  Unable to change comment.
 
Notes:
 If Server is left blank, your computer will be used. Possible failure reasons: Insufficient permissions or unable to contact the computer.
 
Example:
If SetServerComment("This Is My Computer!") Then
  MsgBox "Your comment has been successfully changed."
End If

If SetServerComment("This Is Another Computer!","\\anothercomputer") Then
  MsgBox "The computers comment has been successfully changed."
End If
Compatability:
  Windows 95/98    Windows 2000/NT  



















The USER_INFO Structure
 
Dim SomeUsersInfo As USER_INFO
 
     Name As String     Specifies the username that the information pretains to.
     Fullname As String     Specifies the full name of the user.
     Comment As String     Specifies the comment in the users account.
     UserComment As String     Specifies a comment about this particular user.
 
Example:
Dim MyPDC As String
Dim UsersInfo As USER_INFO
MyPDC = GetPDCName("MyDomain")

UsersInfo = GetUserInfo(MyPDC, "jdoe")

MsgBox "This information is about " & UsersInfo.Name
MsgBox "Users full name is: " & UsersInfo.Fullname
MsgBox "The comment in the account is: " & UsersInfo.Comment
MsgBox "The comment about the user is: " & UsersInfo.UserComment
Compatability:
  Windows 95/98    Windows 2000/NT  



















Contributors for the Network Information/Modification Module (NIMM)

   Uh... whoa guess that would be me. But I can't take all the credit. I'd like to thank Randy Birch from VBnet for his insightful article on the NetUserInfo API. And I'd also like to thank "StephenE" who posted an article about the NetGroupGetUsers API on a message board. Thank's for helping!

-Patrick Herbst
  patrick_herbst@usa.net









Support for the Network Information/Modification Module (NIMM)

   So, you're having problems with NIMM? Well, before you go and email me saying the module doesn't work, check these four things:

1) Are you running NIMM on the right operating system? Check above for the compatibility of the APIs.
2) Do you have sufficient permissions on the domain to use the APIs?
3) Do you have a network? :-)
4) You're using Visual Basic right?

   If you said yes to the above then feel free to email me with your problems. Keep in mind I'm one person and I do have a full-time job :-). I'll try to respond as quickly as possible. If you could put "Network Information/Modification Module" (or "NIMM") as the subject, it'd help me out alot!

Thanks,
-Patrick Herbst
  patrick_herbst@usa.net







































:-)