Solved

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

Posted on 2008-10-08
7
366 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:prunesquallor
7 Comments
 
LVL 30

Expert Comment

by:Zoppo
ID: 22677323
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
0
 
LVL 7

Expert Comment

by:ahalya
ID: 22677524
or you could write a program that continues to run even when the user has logged out.  
0
 
LVL 6

Expert Comment

by:ChristianWimmer
ID: 22677574
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.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:prunesquallor
ID: 22680238
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

0
 
LVL 6

Expert Comment

by:ChristianWimmer
ID: 22680569
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.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 22680587
Since you are detecting every logon anyway, just create a registry value (an arbitrary one) and check it's existence - if it is not there, it is the 1st one. If you use a key and create it with 'REG_OPTION_VOLATILE', it will be cleaned up when the system shuts down.
0
 

Author Closing Comment

by:prunesquallor
ID: 31504557
Thanks very much for your help!

ATB
John B
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now