[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


sending email upon logon

Posted on 2005-04-15
Medium Priority
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
  • 2
  • 2
LVL 16

Expert Comment

ID: 13795392
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

ID: 13795690
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

craylord earned 2000 total points
ID: 13795913
go to www.kixtart.org 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

ID: 13798110
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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