Page 1 of 1 1
Topic Options
#139412 - 2005-05-09 12:05 PM detect when new user logs on?
jifop Offline
Fresh Scripter

Registered: 2004-12-21
Posts: 17
Loc: England
can you use kix to detect if it is the first time a user has logged on to a computer?

basically i want to use kix to call an exe that sets up a computer the first time a new user logs onto it. any ideas how to do this?

thanks

Top
#139413 - 2005-05-09 12:45 PM Re: detect when new user logs on?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I once had to list users in our NT Domain that have never logged in examining the LastLogin property of the user Object.

It somehow depends though on when this property gets modified, so you need to test this (works on NT boxes only with ADSI runtimes installed)

Create a new user and assign this as the logon script, to doublecheck, let it run for a user that has already logged in:

Code:


break on

dim $objUsr
$objUsr = getobject("WinNT://" + @domain + "/" + @userid + ",user")
if not @error
if not vartype($objUsr.LastLogin)
"User " + @userid + " has never logged in before" ?
else
"Last login of " + @userid + " was at " + $objUsr.LastLogin ?
endif
else
"Error retrieving User object..." ?
endif

"Hit any key to quit ..."
get $
exit 0




Edited by Jochen (2005-05-09 12:46 PM)
_________________________



Top
#139414 - 2005-05-09 01:47 PM Re: detect when new user logs on?
jifop Offline
Fresh Scripter

Registered: 2004-12-21
Posts: 17
Loc: England
thanks probably didnt make myself clear but i need to make it so if any user logs on to machine they have never logged on to it runs a script!

any ideas

Top
#139415 - 2005-05-09 01:57 PM Re: detect when new user logs on?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh, so you meant that if any user logs on to any machine the first time a piece f software should be executed?

If so, the only way I see is to maintain a central ini-file or a database that gets updated with any logon ...

May come up with an ini based sample if I undesrtood correctly this time


Edited by Jochen (2005-05-09 01:58 PM)
_________________________



Top
#139416 - 2005-05-09 01:58 PM Re: detect when new user logs on?
jifop Offline
Fresh Scripter

Registered: 2004-12-21
Posts: 17
Loc: England
yeah thats the idea!

bit of a pain i know

Top
#139417 - 2005-05-09 02:43 PM Re: detect when new user logs on?
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I have no idea if it would work or not, but just to throw it out there...could you add a value to the default users run key?
Top
#139418 - 2005-05-09 03:43 PM Re: detect when new user logs on?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Quote:

I have no idea if it would work or not, but just to throw it out there...could you add a value to the default users run key?




Yeah, but that'd would run any time and not just for the first one, no?

K,

Here's how I'd solve this :

Code:


dim $LogonList, $aMachines, $_


$LogonList = @scriptdir + "\logonlist.ini"
$aMachines = split(readprofilestring($LogonList,@userid,"UserLoggedOnTo"),",")


if ascan($aMachines,@wksta) = -1
"Run your executable here!" ?
if not @error ; or whatever it takes to proof successful run
if $aMachines[0]
redim preserve $aMachines[ubound($aMachines) + 1]
endif
$aMachines[ubound($aMachines)] = @wksta
$_ = writeprofilestring($LogonList,@userid,"UserLoggedOnTo",join($aMachines,","))
endif
endif



this will maintain a list of machines any user has logged on to so far and if the current machine doesn't match this list it may execute the thing you need to execute.

hth
_________________________



Top
#139419 - 2005-05-09 03:47 PM Re: detect when new user logs on?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I would look for a date/time stamp on something in the users profile dir to see if there is anything that is older than the current date/time.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139420 - 2005-05-09 03:58 PM Re: detect when new user logs on?
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Quote:


Yeah, but that'd would run any time and not just for the first one, no?





I don't know. I'm not sure if that key is only hit when a new profile logs on or anytime someone logs on.

But on a side note, regardless of the solution it should take into account that a profile may be deleted from a machine and hence the setup exe would need to run again next time they log on.

Top
#139421 - 2005-05-09 04:11 PM Re: detect when new user logs on?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
That's true,

an addtional check for chances the exe make would make sense ...
_________________________



Top
#139422 - 2005-05-09 06:55 PM Re: detect when new user logs on?
jifop Offline
Fresh Scripter

Registered: 2004-12-21
Posts: 17
Loc: England
thankyou, another option is simply to search %userprofile% for kix.aware if not exist run 1strun.exe then create it
Top
#139423 - 2005-05-09 07:24 PM Re: detect when new user logs on?
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
A thought just occurred to me.. You could something like the following:
Code:

IF READVALUE('HKCU\Software\Microsoft\Office\11.0\Outlook','FirsRunDialog')<>'False'
; -- Do whatever
ENDIF



Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#139424 - 2005-05-09 08:02 PM Re: detect when new user logs on?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Nope.
%userprofile% gets filled when the user logs in before anny script or something is executed. So this will always be filled when you check on it.
This way a script that checks on %userprofile% will always see that the user has logged in to the machine at least once before.


Edited by R2D2 (2005-05-09 08:03 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#139425 - 2005-05-09 10:49 PM Re: detect when new user logs on?
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Why not use the HKCU-key in registry:
Code:

If ReadValue('HKCU\Software\KiX','ExeIsRun') <> '1'
; Execute Your exe here
$RC = WriteValue('HKCU\Software\KiX','ExeIsRun','1','REG_SZ')
EndIf


-Erik

Top
#139426 - 2005-05-10 01:42 AM Re: detect when new user logs on?
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Or instead of using a central INI, you could query HKCU\Software\KiX\LoggedOnWorkstations for the workstations a user has logged on before.

Something like this (not tested):
Code:


$loggedon=readvalue('HKCU\Software\KiX\LoggedOnWorkstations',@wksta)
if @error <> 0 ;not logged on before
$cmd='%comspec% /c '+'yoursetup.exe'
shell $cmd
endif
$rc=writevalue('HKCU\Software\KiX\LoggedOnWorkstations',@wksta,@date+' - '+@time,'REG_SZ')


_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#139427 - 2005-05-10 10:27 AM Re: detect when new user logs on?
jifop Offline
Fresh Scripter

Registered: 2004-12-21
Posts: 17
Loc: England
no because you use the logon script to check for a specific file (logged_on.alive) and if it cant find it, it will do something then create it.

there is no way that logged_on.alive is a file used by windows! so its not going to be there until the logon script makes it.

this is a very simple and easy version of the above, also means that if a profile is deleted it will know to set up the user again!

Top
#139428 - 2005-05-10 05:44 PM Re: detect when new user logs on?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
OK. Didn't get this from your previous posts.
Checking for a file to be present is one way to do it. Setting a custom registry value in HKCU is an other. Lots of possibilities. I like the reg setting.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#139429 - 2005-05-11 12:30 AM Re: detect when new user logs on?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I still think checking date/time stamps on existing files is the best way to go. It would be backward compatible for all the existing profiles.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.115 seconds in which 0.047 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