Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-08
7
Medium Priority
?
375 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 31

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
The article covers five tools all IT professionals should know about, as they up productivity by a great deal!
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

886 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