Link to home
Start Free TrialLog in
Avatar of tbaseflug
tbaseflugFlag for United States of America

asked on

sending email upon logon

Am working with W2k - what I need is some form of script or program that will email me when a user logs into the server?
Avatar of craylord
craylord

It would be easier to have the script write the information to a log file on a local server or domain controller. This is what we do with kixtart. You will want a share on a server with the following folders. users need write permissions to this folder.
\\server01\log
\\server01\log\inventory
\\server01\log\inventory\csv
\\server01\log\logins
\\server01\log\logins\computer
\\server01\log\logins\csv
\\server01\log\software
and a text file here
\\server01\log\check3.txt


;--------------------------------------------------------------
; The first portion of the script does five things
;  1)  Writes basic computer information to a text file = NetBIOS
;      name.txt (overwrites)
;  2)  Writes logon time to a text file = username.txt (appends)
;  3)  Writes logon time to a text file = NetBIOS name.txt (appends)
;  4)  Writes all logon info to a .csv file (appends)
;  5)  Writes computer info to a .csv one time only for inventory
;      purposes

Use Z: /Delete /persistent
Use Z: "\\server01\log"

; 1)  Basic computer info for reference

ReDirectOutput ("Z:\Inventory\@WKSTA.txt",1)

  ?"NetBIOS name = "@WKSTA

  ?"Last login by "@USERID

  ?"OS = "@PRODUCTTYPE" with "@CSD

  ?"Memory = "MemorySize(0)" MB"

  ?"Processor type is "@CPU

  ?"Processor speed is "@MHZ

  ?"IP address = "@IPADDRESS0

  ?"MAC address = "@ADDRESS

  ?"This information was gathered on "@DATE" at "@TIME
 
; 2)  Tracks all logons by user

ReDirectOutput ("Z:\Logins\@USERID.txt",0)

  ?@USERID" logged into the "@domain" domain on "@WKSTA" at "@TIME" on "@DATE"   "
 
; 3)  Tracks all logons by computer

ReDirectOutput ("Z:\Logins\Computer\@WKSTA.txt",0)

  ?@USERID" logged into the "@domain" domain on "@WKSTA" at "@TIME" on "@DATE"   "
 
; 4)  Records all logon info to a .csv file

ReDirectOutput ("Z:\Logins\CSV\logins.txt",0)

  ?@USERID","@WKSTA","@DATE","@TIME","@LSERVER","
 
; 5)  Records computer info one time to a .csv file and copies a check file
;     to prevent future writes of same computer

If Exist ("c:\check3.txt")

      Goto "software"
      
EndIf      

ReDirectOutput ("Z:\Inventory\CSV\inventory.txt",0)

?@FULLNAME","@WKSTA","$subnet","WMIQuery("SerialNumber","Win32_BIOS")","WMIQuery("Manufacturer","Win32_ComputerSystem")","WMIQuery("Model","Win32_ComputerSystem")","WMIQuery("name","Win32_Processor")","@MHZ"Mhz,"MemorySize(0)"MB,"WMIQuery("Size","Win32_DiskDrive")","@PRODUCTTYPE","@CSD","WMIQuery("SerialNumber","Win32_OperatingSystem")","WMIQuery("VideoProcessor","Win32_VideoController")","@ADDRESS

Copy "Z:\check3.txt" "c:\check3.txt"


;  The second part of this script performs an inventory of installed software on a PC
;  by examining the portion of the registry where uninstall information is kept.
;  The information is then recorded to a text file = computer name that is overwritten
;  with each successive logon.

:software

ReDirectOutput ("Z:\Software\@HOSTNAME.txt", 1)
?"Software installed on @HOSTNAME as of @DATE"
?

;  Scroll through each subkey

$Index = 0

:Loop1

$KeyName = EnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $Index)
If @ERROR = 0
  Goto DisplayCheck
 
Else
  Goto End
 
EndIf

:DisplayCheck

;  Check for DisplayName string, record information if it exists

$Displayname = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Keyname", "DisplayName")
 
;  DisplayName exists

If @ERROR = 0
  ?$Displayname
  $Index = $Index + 1
  Goto Loop1
 
;  DisplayName does not exist
 
Else
  $Index = $Index + 1
  Goto Loop1

:End

;  Finished checking all subkeys, exit program

Use Z: /Delete /persistent
exit
FUNCTION WMIQuery($what,$where,)
      dim $strQuery, $objEnumerator, $value
      $strQuery = "Select $what From $where"
      $SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
      $objEnumerator = $SystemSet.ExecQuery($strQuery)
      For Each $objInstance in $objEnumerator
            If @Error = 0 and $objInstance <> ""
                  $=execute("$$value = $$objInstance.$what")
                  $WMIQuery="$value"+"|"+"$WMIQuery"
                  EndIf            Next      $WMIQuery=left($WMIQuery,len($WMIQuery)-1)
      exit @error
      ENDFUNCTION
$computer = @wksta
;? WMIQuery2("Services on","Win32_Service")
;? WMIQuery2("Processes on","Win32_Process")
FUNCTION WMIQuery2($what,$where,)
 $wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" + $computer + "/root/cimv2")
 $list = ""
 $objs = $wmi.instancesof($where)
 for each $obj in $objs
 $list = $list + $obj.description  + chr(13) + chr(10)
 next
 $list=Left($list, Len($list))
; ?$what +" "+ $computer + chr(13) + chr(10) + $list
ENDFUNCTION
Exit
Avatar of tbaseflug

ASKER

craylord -

I am an idiot when it comes to OS scripts - how and what do I need to do to get this to run - is it a login script?
ASKER CERTIFIED SOLUTION
Avatar of craylord
craylord

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
craylord -

THanks - let me give it a try - our DC is down right now but will test it right after it gets back online