Announcement

Collapse
No announcement yet.

Is it possible to find out on which machine a user is logged in using active director

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to find out on which machine a user is logged in using active director

    Hello every body. This is my first post on this forum.
    I have a question and its about 12 hour, i have been searching for this on net.
    Is it possible to find out on which machine a user is logged in using active directory?

  • #2
    Re: Is it possible to find out on which machine a user is logged in using active dire

    I can't think of any way through AD apart from scripting.
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

    Comment


    • #3
      Re: Is it possible to find out on which machine a user is logged in using active dire

      [thebox]

      my solution ---> Lock out his account. wait for him to ring the helpdesk. when he does, ask his terminal id.
      Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

      Comment


      • #4
        Re: Is it possible to find out on which machine a user is logged in using active dire

        So Is it possible to find out that on any machine which user is logged in.

        Comment


        • #5
          Re: Is it possible to find out on which machine a user is logged in using active dire

          Muhammad,

          The only real way I know to accomplish what you are asking is to write a script to query all Active Directory computers to determine if the specified username is currently logged on.

          I've provided a script you can modify to accomplish what you need. The script will dynamically query the specified Active Directory domain for all computer accounts, then query them for user sessions. It will compare logged on users to the username you specify and tell you which computers the user is logged onto.

          To make this work, change the strTargetUsername to equal the Active Directory username of the target user (e.g. bjones) and change the objCommand.CommandText to reference the distinguishedName of your domain (e.g. DC=subdomain,DC=domain,DC=com).

          Once you are done, save this as a script file (e.g. FindUser.vbs) and run it from a command prompt by executing cscript FindUser.vbs.


          Script Source Below
          ----

          Option Explicit
          On Error Resume Next
          Dim objConnection, objCOmmand, objRecordset
          Dim strComputer, strTargetUsername
          Const ForReading = 1, ForWriting = 2, ForAppending = 8
          Const ADS_SCOPE_SUBTREE = 2
          strTargetUsername = "ewestfall"
          Set objConnection = CreateObject("ADODB.Connection")
          Set objCommand = CreateObject("ADODB.Command")
          objConnection.Provider = "ADsDSOObject"
          objConnection.Open "Active Directory Provider"
          Set objCommand.ActiveConnection = objConnection
          objCommand.CommandText = _
          "Select Name, Location from 'LDAP://DC=internal,DC=company,DC=com' " _
          & "Where objectClass='computer'"
          objCommand.Properties("Page Size") = 1000
          objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
          Set objRecordSet = objCommand.Execute
          objRecordSet.MoveFirst
          Do Until objRecordSet.EOF
          strComputer = objRecordSet.Fields("Name").Value

          If Not strComputer = "" And VerifyConnectivity(strComputer) Then
          Call IsLoggedOn(strComputer, strTargetUsername)
          End If

          objRecordSet.MoveNext
          Loop
          Public Function IsLoggedOn(strComputer, strTargetUsername)
          Dim objWMIService, objSession, objLoginSession
          Dim colLoginSessions, colSessionList
          Dim bolTargetUserPresent

          bolTargetUserPresent = False

          Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
          Set colLoginSessions = objWMIService.ExecQuery("Select * from Win32_LogonSession Where LogonType=2")

          If colLoginSessions.Count > 0 Then
          For Each objLoginSession In colLoginSessions
          Set colSessionList = objWMIService.ExecQuery("Associators of " _
          & "{Win32_LogonSession.LogonId=" & objLoginSession.LogonId & "} " _
          & "Where AssocClass=Win32_LoggedOnUser Role=Dependent")

          For Each objSession In colSessionList
          If LCase(objSession.Name) = LCase(strTargetUsername) Then
          bolTargetUserPresent = True
          End If
          Next
          Next
          Else
          bolTargetUserPresent = False
          End If

          If bolTargetUserPresent = True Then
          WScript.Echo("Specified user (" & strTargetUsername & ") is logged onto " & UCase(strComputer) & ".")
          End If

          IsLoggedOn = bolTargetUserPresent

          Set objSession = Nothing
          Set objWMIService = Nothing
          Set colSessionList = Nothing
          Set objLoginSession = Nothing
          Set colLoginSessions = Nothing
          End Function
          Public Function VerifyConnectivity(strComputer)
          Dim objShell, objShellExecute

          Set objShell = CreateObject("WScript.Shell")
          Set objShellExecute = objShell.Exec("%comspec% /c ping -l 0 -n 2 -w 3000 " & strComputer)

          If InStr(LCase(objShellExecute.StdOut.ReadAll), "reply from") > 0 Then
          VerifyConnectivity = True
          Else
          VerifyConnectivity = False
          End If

          Set objShellExecute = Nothing
          Set objShell = Nothing
          End Function

          Comment


          • #6
            Re: Is it possible to find out on which machine a user is logged in using active dire

            Try the below command,

            net view | find "username" /I

            This can be run from any machine which is part of domain. This works only on domain computers.

            Comment


            • #7
              Re: Is it possible to find out on which machine a user is logged in using active dire

              Had the same issue the other day, search the event log on DC for the username, it will mention the IP address. Then with the IP do a nslookup for computer name.

              Sorry...didn't see the AD part! not sure with AD just event logs

              Comment


              • #8
                Re: Is it possible to find out on which machine a user is logged in using active dire

                Hi,

                not sure about the AD search that you're asking off but you can always use PsLoggedOn from sysinternal suite to find out which the system.

                Also if your users have home folders mapped to their profile, you can find out the workstation using the computer management->sessions tab.


                Hope this helps your query.!!!!

                Comment

                Working...
                X