Page 1 of 1 1
Topic Options
#3406 - 2000-07-03 06:19 PM login script
Anonymous
Unregistered


hello,
is there a possiblity to let the user
know his last login in a login kix script
win nt network , (nt server 4.0 ) ws
nt server 4, and how?


Top
#3407 - 2000-07-03 07:04 PM Re: login script
Anonymous
Unregistered


If you shell out and do a net user "%username%" /domain it will give you the last login time. you can parse that data out and present it to the user.
Top
#3408 - 2000-07-03 08:20 PM Re: login script
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

the net user %username% /domain contains last login. Interesting for other people. No interesting for the user himself, because after logging in the last login time has be updated before you can get this information.
A possible way is to save the information to a file, which will be read during logging in.

A script for it.

code:

IF setconsole("hide")
ENDIF
;
; NT/95 logon - Kixtart 3.62
;
; (c) scripting@wanadoo.nl - 2000
;
; vs 1.00 - program
;
; 1.00 (20000615) original version.
; - special variables:
; $logon_server="IT company"
; $user_drive="s:"
; - special file:
; $user_drive+"\logon.lst" (file.attributes: hidden/read-only/system)
;
$prgrm_version="1.00"
$prgrm_publication_date="15.6.2000"
;
$time_start=@time
;
$cr=CHR(10)
$lf=CHR(13)
$eol=$lf ; - $cr+$lf -
;
$logon_server="IT company"
$user_drive="s:" ; - variable used by calculation of possible missing "$user" value -

IF (@inwin = 1)
$NT_mode="yes"
ELSE
$NT_mode="no"
ENDIF
IF (len(@ipaddress0) = 0)
$offline_mode="yes"
ELSE
$offline_mode="no"
ENDIF

; --------------------------------------------------------------------------
; - -
; --------------------------------------------------------------------------

$domain=""
$ldomain=""
IF ($NT_mode = "yes")
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
IF (ExistKey($ikey) = 0)
$domain=ReadValue($ikey, "DefaultDomainName")
ENDIF
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
IF (ExistKey($ikey) = 0)
$ldomain=ReadValue($ikey, "CachePrimaryDomain")
ENDIF
ELSE
$ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MSNP2\NetworkProvider"
IF (ExistKey($ikey) = 0)
$domain=ReadValue($ikey, "AuthenticatingAgent")
ENDIF
$ikey="HKEY_LOCAL_MACHINE\Security\Provider"
IF (ExistKey($ikey) = 0)
$ldomain=ReadValue($ikey, "Container")
ENDIF
ENDIF
IF (len($domain) = 0)
IF (len(@ldomain) <> 0)
$domain=@ldomain
ELSE
$domain=@domain
ENDIF
IF (len($domain) = 0)
$domain="~domain" ; - unknown @domain/@ldomain value -
ENDIF
ENDIF
IF (len($ldomain) = 0)
$ldomain=$domain
ENDIF
;
break off
MD "c:\temp"
IF (@error = 0)
ENDIF
IF (RedirectOutput("nul",1) = 0)
ENDIF
flushkb

IF ($NT_mode = "yes")
$time_stop=@time
$log_info="Kixtart-LOG "+$prgrm_version+" script started"
$log_info=$log_info+" for '"+LCASE(@userid)+"'"
$log_info=$log_info+" ("+$time_start+" - '"+@ipaddress0+"')"
IF logevent(0, 1, $log_info, "", "Kixtart LOG @kix")
ENDIF
ENDIF
;
IF setconsole("hide")
ENDIF

; --------------------------------------------------------------------------
; - special variables settings -
; --------------------------------------------------------------------------

$section=substr(@date,3,2)
IF (@ydayno < 10)
$section=$section+"00"+@ydayno
ELSE
IF (@ydayno < 100)
$section=$section+"0"+@ydayno
ELSE
$section=$section+@ydayno
ENDIF
ENDIF
$key=$section+"_"
$key=$key+substr(@date,3,2)+substr(@date,6,2)+substr(@date,9,2)
$key=$key+"_"
$key=$key+@time
$key=$key+" "+$domain

$x=""
$tmp=""
$tmp_short=""

IF (len(@ipaddress0) = 0)
$offline_mode="yes"
IF ($NT_mode = "yes")
$x=$x+"(NT - vs "+$prgrm_version+" - off-line )"
ELSE
$x=$x+"(95 - vs "+$prgrm_version+" - off-line )"
ENDIF
ELSE
$offline_mode="no"
IF (len(@lserver) = 0)
$lserver="~lserver "
ELSE
$lserver=@lserver ; - \\spln99999 -
ENDIF
IF (LCASE($domain) = LCASE($ldomain))
IF ($NT_mode = "yes")
$x=$x+"(NT - vs "+$prgrm_version+" L $domain $lserver)"
ELSE
$x=$x+"(95 - vs "+$prgrm_version+" L $domain $lserver)"
ENDIF
ELSE
IF ($NT_mode = "yes")
$x=$x+"(NT - vs "+$prgrm_version+" - $domain $lserver)"
ELSE
$x=$x+"(95 - vs "+$prgrm_version+" - $domain $lserver)"
ENDIF
ENDIF
ENDIF
$tmp_short=$x

IF (len(@ipaddress0) = 15)
$i=1
$ip_old=@ipaddress0
$ip_new=""
DO
IF (substr($ip_old,$i,1) <> " ")
$ip_new=$ip_new+substr($ip_old,$i,1)
ELSE
$ip_new=$ip_new+"0"
ENDIF
$i=$i+1
UNTIL ($i > 15)
ELSE
$ip_new="xxx.xxx.xxx.xxx"
ENDIF
$x=$x+" "+$ip_new

IF (len(@address) = 0)
$address="xxxxxxxxxxxx"
; $address="xx-xx-xx-xx-xx-xx"
ELSE
$address=@address
; $address= substr(@address,1,2)+"-"+substr(@address,3,2)+"-"+substr(@address,5,2)
; $address=$address+"-"+substr(@address,7,2)+"-"+substr(@address,9,2)+"-"+substr(@address,11,2)
ENDIF
$x=$x+" "+$address

$user=""
IF ($NT_mode = "yes")
$ikey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
IF (ExistKey($ikey) = 0)
$user=ReadValue($ikey, "DefaultUserName")
ENDIF
ELSE
$ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\control"
IF (ExistKey($ikey) = 0)
$user=ReadValue($ikey, "Current User")
ENDIF
ENDIF
IF (len($user) = 0)
$user=@userid
IF (len($user) = 0)
$user="~user"
ENDIF
ENDIF
$x=$x+" "+$user
$tmp_short=$tmp_short+" "+$user

IF (len(@wksta) = 0)
$x=$x+" ~wksta"
$tmp_short=$tmp_short+" ~wksta"
ELSE
$x=$x+" "+@wksta
$tmp_short=$tmp_short+" "+@wksta
ENDIF
IF (len(@fullname) = 0)
IF (len(@comment) = 0)
$x=$x+" ('~fullname')"
ELSE
$x=$x+" ('~fullname'+'"+@comment+"')"
ENDIF
$tmp_short=$tmp_short+" '~fullname'"
$fullname=$user
ELSE
IF (len(@comment) = 0)
$x=$x+" ('@fullname')"
ELSE
$x=$x+" ('"+@fullname+"'+'"+@comment+"')"
ENDIF
$tmp_short=$tmp_short+" '"+@fullname+"'"
$fullname=$user
ENDIF
;
$admin_user="no"
IF (INGROUP("Administrators") = 1) OR (INGROUP("Administrators") = 2)
$admin_user="yes"
ENDIF
IF (INGROUP("Domain Admins") = 1) OR (INGROUP("Domain Admins") = 2)
$admin_user="yes"
ENDIF

$tmp=$x

; --------------------------------------------------------------------------
; - get last user logon information -
; --------------------------------------------------------------------------

$last_logon_message="Last logon by '"+$fullname+"' at "+LCASE(@day)+" "+@mdayno+"-"+LCASE(substr(@month,1,3))+"-"+@year+" "+@time
$last_workstation= "Location pc '"+UCASE(@wksta)+"' of domain '"+UCASE($domain)+"'"
$previous_logon_message="<unknown>"
$previous_workstation="<unknown>"
;
$filename=$user_drive+"\logon.lst"
IF (exist($filename) = 1)
IF (setfileattr($filename, 128) <> 0)
ENDIF
$previous_logon_message=readprofilestring($filename, "last logon", "user")
$previous_workstation=readprofilestring($filename, "last logon", "workstation")
ENDIF
IF (writeprofilestring($filename, "last logon", "user", $last_logon_message) <> 0)
? @serror
ENDIF
IF (writeprofilestring($filename, "last logon", "workstation", $last_workstation) <> 0)
? @serror
ENDIF
IF (setfileattr($filename, 7) <> 0) ; -RHS-
? @serror
ENDIF
;
IF (exist($filename) = 1)
IF (len($previous_logon_message) = 0)
$previous_logon_message="<unknown>"
ENDIF
ENDIF
;
IF ($previous_logon_message <> "<unknown>")
$msg= "Welcome to "+$logon_server+" network"+$lf
$msg=$msg+$lf
$msg=$msg+$lf
$msg= "Note: internal systems must be used only for con-"+$lf
$msg=$msg+" ducting business, or for purpose authorized"+$lf
$msg=$msg+" by management."+$lf
$msg=$msg+$lf
$msg=$msg+"Use is subject to audit at any time by management."+$lf
$msg=$msg+$lf
$msg=$msg+$lf
$msg=$msg+$previous_logon_message+$lf
IF ($admin_user = "yes")
$msg=$msg+$lf
$msg=$msg+$previous_workstation
ENDIF
;
IF (MessageBox($msg, $logon_server, 64, 10) <> 0)
? @serror
ENDIF
ENDIF

; --------------------------------------------------------------------------
; - end -
; --------------------------------------------------------------------------

:end_script

; IF (@priv = "ADMIN")
; color R+/W
; ? "Your are SUPERVISOR!"
; play "0g500f120t"
; sleep 5
; ENDIF

$time_stop=@time
IF ($NT_mode = "yes")
$log_info="Kixtart-LOG "+$prgrm_version+" script completed successfully"
$log_info=$log_info+" for '"+LCASE($user)+"' "+UCASE($domain)
$log_info=$log_info+" ("+$time_start+" - "+$time_stop+" - '"+$ip_new+"')"
IF (len($fullname) > 0)
$log_info=$log_info+" '"+LCASE($fullname)+"'"
$log_info=$log_info+" '"+$previous_logon_message+"'"
$log_info=$log_info+" '"+$previous_workstation+"'"
ENDIF
;
IF logevent(0, 1, $log_info, "", "Kixtart LOG @kix"+"s")
ENDIF
ENDIF
play "0g500f60t"
break on
flushkb


Special variables are:


  • $logon_server which can changed to message box header
  • $user_drive which must be changed to home directory of user.
    the file logon.lst will contain information about last logon.

Example:


  • Last logon by 'MCA' at monday 3-jul-2000 20:00:00
  • Location pc 'PC12345' of domain 'server'

Remark:


  • information also written to eventviewer log.
  • some code is not functionally because it is using by a bigger script.
    part of your request has been extracted.

Greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 957 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.053 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org