Solved

Get uptime of all Computers in Active Directory

Posted on 2009-07-09
3
752 Views
Last Modified: 2012-08-14
I would like a VB.Net Console Application that can get the Uptime and currently logged on user of all powered-up computers in the Active Directory, and write this data to a SQL Database.

Please help.

I am using Visual Studio 2005.

Thanks.
0
Comment
Question by:ive5005s
3 Comments
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 50 total points
ID: 24816923
This will retrieve the computer names from a specific OU from AD and dump them into a list box:
Private Sub GetComputers()
        Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://rootDSE")
        Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
        Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://OU=YourOU," & DomainDN)
        Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
        Dim sComputerName As String
        Dim deUser As DirectoryServices.DirectoryEntry
        ADSearch.Filter = "(&(objectCategory=computer)(objectClass=user))"
        ADSearch.SearchScope = DirectoryServices.SearchScope.Subtree
        Dim results As DirectoryServices.SearchResultCollection = ADSearch.FindAll()
        Dim ObjectFound As DirectoryServices.SearchResult
        For Each ObjectFound In results
            deUser = ObjectFound.GetDirectoryEntry
            sComputerName = String.Empty & ObjectFound.GetDirectoryEntry().Properties.Item("cn").Value
            If sComputerName.Trim.Length > 0 Then
                Me.lstComputers.Items.Add(sComputerName)
             End If
        Next
        Me.lstComputers.Sorted = True
    End Sub

I don't know how to determine uptime or logged on user.
Do you know anything about writing data to a database?
FYI, this question is pretty ambitious, especially considering the number of points offered.
0
 
LVL 41

Assisted Solution

by:graye
graye earned 50 total points
ID: 24817543
Take a look at the VB.Net source code for the following example... it will use Active Directory to "poll the network" to find the currently logged in user.   It doesn't write to a Database, nor does it get the uptime, but I'd bet it'd get you started on your way.
http://www.emmet-gray.com/Programs/WhoIsLoggedOn.zip
The snippnet below is how you'd get the LastBoot time for each PC

' Add a reference to "System.Management"

Imports System.Management 

 

        Dim wmi As ManagementClass

        Dim obj As ManagementObject
 

        wmi = New ManagementClass("\\" & RemotePC & "\root\cimv2:Win32_OperatingSystem")

        For Each obj In wmi.GetInstances()

            If Not IsNothing(obj("LastBootUpTime")) Then

                pLastBoot = ManagementDateTimeConverter.ToDateTime(obj("LastBootUpTime").ToString)

            End If

        Next

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now