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

x
?
Solved

sending email upon logon

Posted on 2005-04-15
4
Medium Priority
?
278 Views
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?
0
Comment
Question by:tbaseflug
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:craylord
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.
\\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
0
 

Author Comment

by:tbaseflug
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?
0
 
LVL 16

Accepted Solution

by:
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

\\server01\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"

0
 

Author Comment

by:tbaseflug
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
0

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