Reputation: 31
I am trying to get how many days ago Store-bought HP or Dell Windows 10 PC was first used, using c#/windows forms. What I mean by this is the date the computer went through the intial setup, such as creating a Username and password, etc.
Getting the install date from HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate will not work, as features updates change that date.
My hope is that there is a folder or file that is created when the PC is first setup/used, and is not changed even with feature updates like the Creator's Update, anniversary update, etc.
Does any know of such a folder or file, or another way to get some info like this through C#?
Edit: These suggested folders/files creations dates are lost with creators update on the Virtual machine I am using or are older then install. C:\Windows\system.ini C:\Windows\win.ini C:\Users\User C:\bootmgr C:\bootnxt C:\$Recycle.Bin
Edit:This is not a duplicate of the suggested duplicate, as I need to know original install date even if a feature update like the Creator's update has happened. There was a similar post, however none of the answers worked for me.
Upvotes: 1
Views: 1059
Reputation: 37020
Update I modified the answer to loop through all special folders, since I found some that were older than the oldest user folder
This is not at all guaranteed, hopefully someone can tell me if it's wrong and I'll delete it, but one idea is to get the oldest creation date of the SpecialFolder
objects:
static void Main()
{
// This will hold the oldest date, so start it at MaxValue
var oldestDate = DateTime.MaxValue;
// Loop through each defined special folder
foreach (Environment.SpecialFolder specialFolder in
Enum.GetValues(typeof(Environment.SpecialFolder)))
{
// Get the path to this folder
var folderPath = Environment.GetFolderPath(specialFolder);
// Some special folders may not exist, so verify the path first
if (Directory.Exists(folderPath))
{
// If the created date of this folder is older, update our variable
var createDate = Directory.GetCreationTime(folderPath);
if (createDate < oldestDate) oldestDate = createDate;
}
}
Console.WriteLine($"The oldest speical folder was created on: {oldestDate}");
Console.Write("\nDone!\nPress any key to exit...");
Console.ReadKey();
}
Update 2
Getting the creation of the windows root directory also gives the oldest time (at least for me). Possibly this is simpler?
var createDate = Directory.GetCreationTime(Path.GetPathRoot(
Environment.GetFolderPath(Environment.SpecialFolder.Windows)));
Upvotes: 1
Reputation: 1143
systeminfo|find /i "original"
you can use this code in C#
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C systeminfo.exe|find /i \"original\" ";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
OR you can do in more simple way to check the creation date of Users Directory
var date = Directory.GetCreationTime(@"C:\users");
You can create an app and read the results from this command :)
Upvotes: 2