Articles → .NET → Get Lock And Unlock Information Of The System Using C#

Get Lock And Unlock Information Of The System Using C#






Steps




  1. Create 2 console applications (one for lock and other for unlock)
  2. Write code to log lock and unlock time in a text file.
  3. Schedule both the applications using task scheduler

Create 2 Console Applications (One For Lock And Other For Unlock)




  1. Lock - to capture system lock time in the text file
  2. 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




  1. Open task scheduler.
  2. Click on ‘Create Task’
  3. Picture showing the create task link for creating the Task in the task scheduler
    Click to Enlarge

  4. In the popup window, enter the name as ‘Lock’ in ‘General’ tab (we can give any name here).
  5. Picture showing the create task window to enter the task details
    Click to Enlarge

  6. Go to ‘Trigger’ tab.
  7. Click on the ‘New…’ button, another popup window appears.
  8. In the pop up window, select ‘Begin the task’ as ‘On workstation lock’ and click Ok.
  9. Picture showing setting the trigger on the task
    Click to Enlarge

  10. Go to ‘Actions’ tab.
  11. Click on ‘New…’ button. Another pop up window appears
  12. Browse the exe file of ‘Lock’ and click ok.
  13. Picture showing setting the action on the trigger
    Click to Enlarge

  14. Finally close the task scheduler ‘Create task’ window.


  1. ‘Name’ in the ‘General’ tab will be ‘Unlock’ (we can give any name here).
  2. While creating a new trigger, the value of ‘Begin the task’ would be ‘On workstation Unlock’.
  3. In ‘Actions’ tab, unlock.exe would be selected.

Output




Picture showing the output lock and unlock information on notepad
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, March 17, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250