Solved

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

Posted on 2008-10-08
7
370 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows 10 pin current folder to quick access not working 12 45
Windows Updates 14 78
Windows 2008R2 update 3 32
windows driver update command 13 15
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

738 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