473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get Computer State (Locked, Stand By) in C#

Hi,

I would like to get the status of System State like whether its Locked, or Logged.
I am using C# and application is WinForm.

Advance thanks for the help

Regards,
Surya
Feb 14 '08 #1
3 13899
Plater
7,872 Expert 4TB
I think if you found out the currently logged in user, you would get your result.
If there is no logged in user, then you're logged out.
I suppose if someone LOCKS the pc, then they are still logged in. Hmm. Maybe cycling through the running proccess (System.Diagnostics.Process.GetCurrentProcess()) and looking at the user names of running programs could be used as well.


For currently logged on user, I would take a look at:
Expand|Select|Wrap|Line Numbers
  1. System.Security.Principal.WindowsIdentity.GetCurrent()
  2.  
and it's overloads to see what is correct usage.



There may in fact be a much easier solution, but I can't think of it right now.

I also found this:
http://www.thescripts.com/forum/thread536508.html
Feb 14 '08 #2
Hi,
I found the solution.
Expand|Select|Wrap|Line Numbers
  1. using Microsoft.Win32;
  2.  
  3. Constrctor()
  4. {
  5. SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
  6. }
  7.  
  8. ~Constrctor()
  9. {
  10. //Do this during application close to avoid handle leak
  11. Microsoft.Win32.SystemEvents.SessionSwitch -= new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
  12. }
  13.  
  14.  
  15. void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
  16.         {
  17.             switch (e.Reason)
  18.             {
  19.                 case SessionSwitchReason.SessionLogon:
  20.                 case SessionSwitchReason.SessionUnlock:
  21.                     break;
  22.  
  23.                 case SessionSwitchReason.SessionLock:
  24.                 case SessionSwitchReason.SessionLogoff:
  25.  
  26.                     break;
  27.             }
  28.         }
  29.  
Event is fired when ever Pc is locked, Unlocked....

Thank You
Surya
Mar 10 '08 #3
Plater
7,872 Expert 4TB
Excellent find .
Mar 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bardolator | last post by:
Hello I have a stand alone Java application that uses SQL Server 2000 on the same machine. Sometimes, when we run the applications and follow a certain steps, the SQL server locks some of the...
1
by: Steve Amey | last post by:
Hi all In my .NET application (maybe run as a service), is there a way to know when my computer is locked? I want to write an app that logs when the computer has started and when it has been...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
2
by: jim-on-linux | last post by:
py help, The file below will run as a stand alone file. It works fine as it is. But, when I call it from another module it locks my computer, The off switch is the only salvation. This...
8
by: Andrew Teece | last post by:
Hope someone can help. We are trying to deploy an ASP.Net 2.0 application to a 3-node webfarm. The application uses the ReportViewer control in local mode, hence we need session state. Because we...
1
by: tricard | last post by:
Good afternoon all, I have recently been trying my hand out at the ADO model as before I have only used DAO (just thought I would expand my knowledge a bit). The problem I am having is that...
7
by: tman69 | last post by:
I apologize in advance for the length of this posting and will attempt to simplify as much as possible. I have an automation application in MS Access which generates reports in Excel and emails...
2
by: Josh Burkard | last post by:
Hello For a alarm-system in our company i want to show a message-window at the users screen while some events, even the users computer (Win XP SP 2 in domain) is locked. How can i show a...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.