Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Any way to find who all in the network use Domain/Admin credential to login/Remote login

Hi,

Any way to find who all in the network use Domain/Admin credential to login/Remote login.
If anyone has used domain/administrator credential to loggin.

Regards
Sharath
Avatar of RobSampson
RobSampson
Flag of Australia image

Sharath, it is not possible to know "who" has used the Administrator account to log in.  You *may* be able to know "where" they have logged in, if your Domain Controllers are set to Audit logins.  You could interrogate the Event Log to filter the Audit list by Administrator logons, and you can see which computer was used.

The other way to do this, which I use, is to include in your logon script, a script that records the time and computer for each user to a text file.  Then, at any time, you can open the Administrator.txt file, and you will see where that account has been used.

Regards,

Rob.

'=======================
Option Explicit
'On Error Resume Next

Dim WSHShell, WSHProcess, strUserName, strHostName, strCommand

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set WSHShell = CreateObject("Wscript.Shell")
Set WSHProcess = WSHShell.Environment("Process")

strUserName = WSHProcess("USERNAME")
strHostName = WSHProcess("COMPUTERNAME")


Dim objShell, strComputer, objWMIService, colComputerIP, IPConfig, intIPCount, strIPAddress, strFullIP
Dim  objFSO, objFile, strOutputFile
Dim strContents, arrLinesInFile, intLineCount, intMaxLinesAllowed

strComputer = "."

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objShell = CreateObject("WScript.Shell")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputerIP = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration")
 
For Each IPConfig in colComputerIP
      If Not IsNull(IPConfig.IPAddress) Then
        For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
                strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCount) & "~"
            Next
      End If
Next

If InStr(strIPAddress, "192.168.10.") > 0 Then
      strFullIP = Mid(strIPAddress, InStr(strIPAddress, "192.168.10."), InStr(InStr(strIPAddress, "192.168.10."), strIPAddress, "~") - InStr(strIPAddress, "192.168.10."))
ElseIf InStr(strIPAddress, "192.168.100.") > 0 Then
      strFullIP = Mid(strIPAddress, InStr(strIPAddress, "192.168.142."), InStr(InStr(strIPAddress, "192.168.142."), strIPAddress, "~") - InStr(strIPAddress, "192.168.142."))
Else
      strFullIP = "UNKNOWN"
End If

If Len(strFullIP) > 1 And Right(strFullIP, 1) = "~" Then
      strFullIP = Left(strFullIP, Len(strFullIP) - 1)
End If
      
' /////// Define the text file name as the name of the user //////////
strOutputFile = "\\SERVER\UserLogins$\" & strUserName & ".txt"

On Error Resume Next

'/////// Open the user's text file for reading first to be able to count the number of lines ///////
'Set objFile = objFSO.OpenTextFile ("\\SERVER\UserLogins$\" & strOutputFile, ForAppending, True)
Set objFile = objFSO.OpenTextFile (strOutputFile, ForReading, True)

'////// Set this value to the maximum number of entries allowed per user's text file
'////// Set this value to 0 or -1 to have unlimited lines
intMaxLinesAllowed = -1

strContents = ""
strContents = objFile.ReadAll

If Len(strContents) > 0 Then
      arrLinesInFile = Split(strContents, vbCrLf)
      If intMaxLinesAllowed > 0 Then
            If UBound(arrLinesInFile) > (intMaxLinesAllowed - 1) Then
                  strContents = ""
                  For intLineCount = 0 To (intMaxLinesAllowed - 2)
                        strContents = strContents & arrLinesInFile(intLineCount) & VbCrLf
                  Next
                  strContents = strContents & arrLinesInFile((intMaxLinesAllowed - 1))
            End If
      End If
End If

'MsgBox "There are " & UBound(arrLinesInFile) & " lines in the file before adding 1."

Set objFile = objFSO.OpenTextFile (strOutputFile, ForWriting, True)
objFile.Write(Pad_String(strFullIP, 20, "Right", " ") & "|  " & Pad_String(strHostName, 24, "Right", " ") & "|  " & Now & VbCrLf & strContents)

objFile.Close

On Error Goto 0


'*************************************************************

Function Pad_String(strOriginalString, intTotalLengthRequired, strDirection, strCharacterToPadWith)

      'Declare variants used in this function.
      Dim intPadCount, strPadding
      
      'Convert imput direction to lower case.
      strDirection = LCase(strDirection)
      
      'Trim input string if larger than pad length
      If (Len(strOriginalString) > intTotalLengthRequired) Then
            strOriginalString = Left(strOriginalString, intTotalLengthRequired)
      End If
      
      'Take first character if input pad character is more than a single character.
      If (Len(strCharacterToPadWith) > 1) Then
            strCharacterToPadWith = Left(strCharacterToPadWith, 1)
      End If
      
      'Generate padding string
      For intPadCount = 1 to intTotalLengthRequired - Len(strOriginalString)
            strPadding = strCharacterToPadWith & strPadding
      Next
      
      If strDirection <> "left" And strDirection <> "right" Then
            strDirection = "right"
      End If
      
      'Return padded string based on direction.
      Select Case strDirection
            Case "left"
                  Pad_String = strPadding & strOriginalString
            Case "right"
                  Pad_String = strOriginalString & strPadding
      End Select

End Function

'*************************************************************
'==============
Avatar of bsharath

ASKER

The above script.Should i put it in the logon script?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Rob,

I am guessing that I should modify these lines right?

If InStr(strIPAddress, "192.168.10.") > 0 Then
      strFullIP = Mid(strIPAddress, InStr(strIPAddress, "192.168.10."), InStr(InStr(strIPAddress, "192.168.10."), strIPAddress, "~") - InStr(strIPAddress, "192.168.10."))
ElseIf InStr(strIPAddress, "192.168.100.") > 0 Then
      strFullIP = Mid(strIPAddress, InStr(strIPAddress, "192.168.142."), InStr(InStr(strIPAddress, "192.168.142."), strIPAddress, "~") - InStr(strIPAddress, "192.168.142."))
Else
      strFullIP = "UNKNOWN"
End If


Thanks
Sean