Solved

Get uptime of all Computers in Active Directory

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
backup program with robocopy 6 45
VB.NET Textbox input validation 4 37
Vector, list Questions R 6 31
Adding items to a C# list incrementally 5 30
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

860 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