Solved

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

Posted on 2008-10-08
7
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Configuring Remote Assistance for use with SCCM
Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

636 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