How to Save Your Computer's Startup History in C#

Learn how to save the history of when your computer started.

Let's write a simple program that will run automatically when your computer starts and will log the startup time in a text file.
 
Step 1: Create a simple Console application in C# and write the following code in the main method. Here we're appending current date time to a text file.

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.IO;  
  6. namespace autologin  
  7. {  
  8. class Program  
  9. {  
  10. static void Main(string[] args)  
  11. {  
  12. File.AppendAllText(@"C:\logintime.txt", Environment.NewLine);  
  13. File.AppendAllText(@"C:\logintime.txt""Your Login Time is : " + DateTime.Now.ToString());  
  14. }  
  15. }  
  16. }  
Step 2: Build your application and get the exe file.
 
Step 3: Goto Control Panel->Sheduled task->Add sheduled Task->Next>Browse
 
Step 4: Browse your exe file that we just created in the previous step.
 
Step 5: Set option when my computer starts and finish wizard.
 
Now when your computer will started, this exe will execute the code and the current date time will be appended to the text file.