Solved

Get uptime of all Computers in Active Directory

Posted on 2009-07-09
3
762 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

930 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

11 Experts available now in Live!

Get 1:1 Help Now