?
Solved

Get uptime of all Computers in Active Directory

Posted on 2009-07-09
3
Medium Priority
?
803 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 200 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 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress
Suggested Courses

770 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