Articles → .NET → Get Lock And Unlock Information Of The System Using C#
Get Lock And Unlock Information Of The System Using C#
Steps
- Create 2 console applications (one for lock and other for unlock)
- Write code to log lock and unlock time in a text file.
- Schedule both the applications using task scheduler
Create 2 Console Applications (One For Lock And Other For Unlock)
- Lock - to capture system lock time in the text file
- Unlock – to capture system unlock time in text file
Write Code To Log Lock And Unlock Time In Text File
using System;
using System.IO;
namespace Unlock {
class Program {
static void Main(string[] args) {
File.AppendAllText(@ "C:\test\info.txt", "Unlock time is " + DateTime.Now.ToString() + Environment.NewLine);
}
}
}
using System;
using System.IO;
namespace Lock {
class Program {
static void Main(string[] args) {
File.AppendAllText(@ "C:\test\info.txt", "Lock time is " + DateTime.Now.ToString() + Environment.NewLine);
}
}
}
Schedule Both The Applications Using Task Scheduler
- Open task scheduler.
- Click on ‘Create Task’
Click to Enlarge
- In the popup window, enter the name as ‘Lock’ in ‘General’ tab (we can give any name here).
Click to Enlarge
- Go to ‘Trigger’ tab.
- Click on the ‘New…’ button, another popup window appears.
- In the pop up window, select ‘Begin the task’ as ‘On workstation lock’ and click Ok.
Click to Enlarge
- Go to ‘Actions’ tab.
- Click on ‘New…’ button. Another pop up window appears
- Browse the exe file of ‘Lock’ and click ok.
Click to Enlarge
- Finally close the task scheduler ‘Create task’ window.
- ‘Name’ in the ‘General’ tab will be ‘Unlock’ (we can give any name here).
- While creating a new trigger, the value of ‘Begin the task’ would be ‘On workstation Unlock’.
- In ‘Actions’ tab, unlock.exe would be selected.
Output
Click to Enlarge