Question : Script to monitor the logged in user. If a different person found then email.

Hi,

Script to monitor the logged in user. If a different person found then email.
I have a txt file that has the machine name and the user name. to whome the machine is allotted.
Machine name;username

I want a script to scan all machines in this txt file every 4 hrs. If there is a mismatch then email.

powershell or vbs script.

regards
Sharath

Answer : Script to monitor the logged in user. If a different person found then email.

I've modified the code as requested.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
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
Random Solutions  
 
programming4us programming4us