sending email upon logon

Posted on 2005-04-15
Last Modified: 2010-04-12
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?
Question by:tbaseflug
    LVL 16

    Expert Comment

    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.
    and a text file here

    ; 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)

    ; 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"

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


    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.


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

    ;  Scroll through each subkey

    $Index = 0


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


    ;  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
      $Index = $Index + 1
      Goto Loop1
    ;  DisplayName does not exist
      $Index = $Index + 1
      Goto Loop1


    ;  Finished checking all subkeys, exit program

    Use Z: /Delete /persistent
    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")
                      EndIf            Next      $WMIQuery=left($WMIQuery,len($WMIQuery)-1)
          exit @error
    $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)
     $list=Left($list, Len($list))
    ; ?$what +" "+ $computer + chr(13) + chr(10) + $list

    Author Comment

    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?
    LVL 16

    Accepted Solution

    go to and download kixtart.
    On your domain controller there should be a share called netlogon. Extract the kixtart program files there. This is where the user will run the kixtart.exe from. If you don't have that share, you can create a share elsewhere and point to it in Active Directory. I'll describe that later.

    Copy the script above into a .txt file and rename it as a .kix file i.e. login.kix
    Add this in a line before the net use...
    break on
    break on will let the script be cancelled by pushing ctrl + c without logging the user off. helpful for testing. Place this login.kix with the kixtart programs in the share.

    In the user properties under the profile tab enter this into the login script box.
    kix32.exe login.kix
    If you don't have a netlogon share you can create a share elsewhere. Put the kixtart program in that share as well as the login.kix


    If you place the share elsewhere, you will have to put the path in the login script box instead.
    \\server01\kix\kix32.exe "\\server01\kix\login.kix"


    Author Comment

    craylord -

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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
    Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now