Link to home
Start Free TrialLog in
Avatar of prunesquallor
prunesquallor

asked on

Microsoft, Windows, 2000 to Vista, How to detect the first logon after boot

I am developing a program that will run every time a user logs on under Windows. However, I want this program to alter its processing according to if it is the first logon after boot.

Is there any way to detect that the current logon is the first one after boot via some registry key or other?
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi prunesquallor,

well, the only idea I have would be to let run a program (i.e. maybe the same with a command line paramter which indicates a system boot occured) at system startup by adding it to 'HKEY_LOCALMACHINE\Software\...\Windows\CurrentVersion\Run'. In this case i.e. the program could write a file that indicates the system was bootet.

Then when the program runs again when a user logged in the program can check if that file exists. If so it can do what should be done when the first user logs in and then delete that file, so with following logins the program knows they're not the first login.

Hope that helps,

ZOPPO
or you could write a program that continues to run even when the user has logged out.  
Yes, create a service and connect to the SENS COM API. You'll get notified when a user logs on. In this way you can track down the first logon even if it is a remote session.
Avatar of prunesquallor
prunesquallor

ASKER

Thanks for the comments:

1. I thought of using eiter Run or RunOnce in that sort of way, but I believe there is an issue in that my program is also starting by a similar mechanism. There doesn't seem to be any way of guaranteeing the order in which programs run by these keys are started. I know there are documents stating that there is a certain order, for at least groups or Run keys, but I've noted by tests the timings of autorun programs, and their order, is quite variable.

2. Are you implying a service? The progarm interacts with the user, so actually has to pick up on the login event, and I've had it beaten into my head that services should not display GUIs. How would it work?

3. I suspect a service might work, but again are there timing issues as in point 1? Do you happen to have a ref on the API - I've looked in the Windows SDK help and can find nothing (presumably I'm guessing at the wrong words!).

In the end, I actually wanted to avoid writing another program as the system is gettting fairly complex and messy already. I believe Windows itself must know this is the first login after boot, so was wondering if that information was accessible directly in some way ... I'm beginning to suspect not!

ATB

John B

I guess the SENS API is much earlier called in the logon process than any other (besides WinlogonNotification) mechanism.
But if you stick to WindowsXP and ignore WindowsVista (not supported) you can also try Winlogon Notification API. It surely works before any other mechanism can react.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much for your help!

ATB
John B