Dim objFSO, objFile, strBuffer, arrUser, strCurrentUser
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
'On the next line edit the file name and path'
Set objFile = objFSO.OpenTextFile("C:\eeTesting\sharath1.txt")
Do Until objFile.AtEndOfStream
strBuffer = objFile.ReadLine
arrUser = Split(strBuffer, ";")
strCurrentUser = GetUserName(arrUser(0))
If strCurrentUser <> arrUser(1) Then
SendMsg arrUser(0), strCurrentUser, arrUser(1)
End If
Loop
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
On Error Goto 0
WScript.Quit
Function GetUserName(strComputer)
Dim objWMIService, colItems, objItem, arrTemp
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
arrTemp = Split(objItem.UserName, "\")
GetUserName = arrTemp(1)
Next
Set objWMIService = Nothing
Set colItems = Nothing
Set objItem = Nothing
On Error Goto 0
End Function
Sub SendMsg(strComputer, strUser, strOwner)
Dim olkApp, olkMsg
Set olkApp = GetObject(,"Outlook.Application")
Set olkMsg = olkApp.CreateItem(0)
With olkMsg
'On the next line edit the email address'
.To = "[email protected]"
'On the next line edit the subject"
.Subject = "Your Subject Goes Here"
'On the next line edit the message text as desired'
.Body = "The user " & strUser & " is logged in to the computer " & strComputer & " where as it's " & strOwner & "'s machine."
.Send
End With
Set olkMsg = Nothing
Set olkApp = Nothing
End Sub
|