Solved

Get uptime of all Computers in Active Directory

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
batch file or script 4 47
Stop Git from being my repository 1 19
Oracle programming for starter 14 27
Web page design problem 3 13
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
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 …

763 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