Author: Brian Yule (byule at PembrokeTechnology.com)
Download... the project. (114 kb)
Screenshot
This example shows how to retrieve various network information for your and other PCs on the network, while hiding the
incredible complexity of it by wrapping the API calls into a nice object hierarchy. The code
list all PCs in your domain. Then for each one it retrieves the following:
- Local Groups (e.g. Administrators, Guests, etc...)
- Global Groups
- Scheduled Jobs
- Network Sessions
- Shared Resources (shared drives, printers, etc...)
- Installed Transports (TCP/IP, netbios, etc...)
- Network Connections (including mapped drives)
- Local Disks
- Local Users and Details on each user.
The code below gives a glimpse of how easy it is to retrieve various information. So to start, create a form, then add
8 listboxes (leave names as default). Then create one combo box. Then paste the code below into your form. Or you could download the
linked project.
| Add the following to Module or Class |
Private Sub Form_Load()
Dim servers As NetServerInfoL101Collection
Dim server As NetServerInfoL101
Set servers = sL.NTL101
For Each server In servers
Combo1.AddItem (server.Name)
Next
If Combo1.ListCount > 0 Then Combo1.ListIndex = 0
End Sub
Private Sub Combo1_Click()
With sL.NTL101.Item(Combo1.ListIndex + 1)
Dim LocalGroups As NetLocalGroupL1Collection
Dim LocalGroup As NetLocalGroupL1
Set LocalGroups = .Groups.LocalGroupsL1
List1.Clear
For Each LocalGroup In LocalGroups
List1.AddItem (LocalGroup.Name)
Next
Dim Users As NetUserinfoL3Collection
Dim User As netuserinfol3
Set Users = .Users.LocalEnumUsersL3
List2.Clear
For Each User In Users
List2.AddItem (User.Name)
Next
If List2.ListCount > 0 Then List2.ListIndex = 0
Dim Jobs As NetScheduleJobCollection
Dim Job As NetScheduleJob
Set Jobs = .Schedule.Jobs
List3.Clear
For Each Job In Jobs
List3.AddItem (Job.Command)
Next
Dim Sessions As NetSessionInfoL2Collection
Dim Session As NetSessionInfoL2
Set Sessions = .Sessions.SessionsL2
List4.Clear
For Each Session In Sessions
List4.AddItem (Session.Name)
Next
Dim Shares As NetShareInfoL2Collection
Dim Share As NetShareInfoL2
Set Shares = .Shares.SharesL2
List5.Clear
For Each Share In Shares
List5.AddItem (Share.Name)
Next
Dim Transports As NetTransportInfoL1Collection
Dim Transport As NetTransportInfoL1
Set Transports = .TransportInfo.TransportsL1
List6.Clear
For Each Transport In Transports
List6.AddItem (Transport.TransportName)
Next
Dim Uses As NetuseinfoL2Collection
Dim Use As NetUseInfoL2
Set Uses = .Use.UseL2
List7.Clear
For Each Use In Uses
List7.AddItem (Use.RemoteShareName & " " & _
IIf(Len(Use.LocalDeviceName) > 0, "(" & Use.LocalDeviceName & ")", ""))
Next
Dim Disks As Collection
Dim Disk As Variant
Set Disks = .Disks
List8.Clear
If Not Disks Is Nothing Then
For Each Disk In Disks
Call List8.AddItem(CStr(Disk))
Next
End If
Dim Groups As NetGroupL2Collection
Dim Group As NetGroupL2
Set Groups = .Groups.GlobalGroupsL2
List9.Clear
For Each Group In Groups
List9.AddItem (Group.Name)
Next
End With
End Sub
Private Sub List2_Click()
Dim User As netuserinfol3
Set User = sL.NTL101.Item(Combo1.ListIndex + 1).Users.LocalEnumUsersL3.Item(List2.ListIndex + 1)
With List10
.Clear
.AddItem ("Account Dissabled: " & User.AccountDissabled)
.AddItem ("Account Expires: " & User.AccountExpires)
.AddItem ("Account Locked Out: " & User.AccountLockedOut)
.AddItem ("Accounts Operator: " & User.AccountsOperator)
.AddItem ("Account Type: " & User.AccountType)
.AddItem ("Bad Password Count: " & User.BadPasswordCount)
.AddItem ("Code Page: " & User.CodePage)
.AddItem ("Comment: " & User.Comment)
.AddItem ("Communications Operator: " & User.CommunicationsOperator)
.AddItem ("Country Code: " & User.CountryCode)
.AddItem ("Dont Expire Password: " & User.DontExpirePassword)
.AddItem ("Encrypted Text Password Allowed: " & User.EncryptedTextPasswordAllowed)
.AddItem ("Full Name: " & User.FullName)
.AddItem ("Home Directory: " & User.HomeDirectory)
.AddItem ("Home Directory Drive: " & User.HomeDirectoryDrive)
.AddItem ("Home Directory Required: " & User.HomeDirectoryRequired)
.AddItem ("Last Logoff: " & User.LastLogoff)
.AddItem ("Last Logon: " & User.LastLogon)
.AddItem ("Logon Server: " & User.LogonServer)
.AddItem ("Max Storage: " & User.MaxStorage)
.AddItem ("Name: " & User.Name)
.AddItem ("Not Delegated: " & User.NotDelegated)
.AddItem ("Number Of Logons: " & User.NumberOfLogons)
.AddItem ("Parameters: " & User.Parameters)
.AddItem ("Password: " & User.Password)
.AddItem ("Password Age: " & User.PasswordAge)
.AddItem ("Password Cant Change: " & User.PasswordCantChange)
.AddItem ("Password Expired: " & User.PasswordExpired)
.AddItem ("Password Not Required: " & User.PasswordNotRequired)
.AddItem ("Primary Group Id: " & User.PrimaryGroupId)
.AddItem ("Print Operator: " & User.PrintOperator)
.AddItem ("Privilege: " & User.Privilege)
.AddItem ("Profile: " & User.Profile)
.AddItem ("Script Executed: " & User.ScriptExecuted)
.AddItem ("Script Path: " & User.ScriptPath)
.AddItem ("Server Operator: " & User.ServerOperator)
.AddItem ("Smartcard Required: " & User.SmartcardRequired)
.AddItem ("Units Per Week: " & User.UnitsPerWeek)
.AddItem ("User Comment: " & User.UserComment)
.AddItem ("User Id: " & User.UserId)
End With
End Sub
To get in touch with the author of this example, email Brian Yule at byule at PembrokeTechnology.com