1

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.

Makanar
  • 31
  • 5
  • @MickyD OP said install date does not work for their situation. – itsme86 Sep 29 '17 at 21:39
  • Did you try just looking at the created date for the folders in C:\Users and getting the oldest one? – itsme86 Sep 29 '17 at 21:40
  • Some ideas here: https://stackoverflow.com/a/44539474/369 – Blorgbeard Sep 29 '17 at 21:41
  • @itsme86 The creation date on the C:\User\User folder(Oldest user) on the Virtual Machine I am using has the date the PC was updated to 1703(Creators Update). – Makanar Sep 29 '17 at 21:52
  • @itsme86 agreed. I just tested it and it seems a recent Windows Update changed it on the 19th. grr –  Sep 29 '17 at 21:58
  • 1
    The problem is the creators update is a new windows install. That's how Microsoft updates for it's "service packs" now. It does a clean install then uses the "File and User Settings Transfer Wizard" to migrate all the user profiles over to the new install. – Scott Chamberlain Sep 29 '17 at 22:02
  • If I run `var createdDate = Directory.GetCreationTime(@"C:\Users\Default User");`, I get a date that's older than the Creators update release, but I'm not sure this is at all accurate. – Rufus L Sep 29 '17 at 23:24

2 Answers2

2
systeminfo|find /i "original" 

enter image description here

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 :)

Thiago Loureiro
  • 1,041
  • 13
  • 24
1

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)));
Rufus L
  • 36,127
  • 5
  • 30
  • 43
  • That is giving me 3/18/2017. Windows was 9-29-2017 at 2:36p and creators update at 4:40p. – Makanar Sep 30 '17 at 00:04
  • The C:\Users\User\Desktop date is 2:36p however, the correct time. Perhaps there is a way to get that, without knowing which user is the oldest(as I will not for my application) – Makanar Sep 30 '17 at 00:06
  • Yes, you can get the desktop date, it is one of the special folders. Notice that I updated the answer to look through all special folders instead of just the users. But why do you say 3/18/2017 is not the correct date? It is older than the date you're saying is correct. – Rufus L Sep 30 '17 at 00:12
  • I also updated the answer with how to get the create date of the Windows directory (at the bottom, under **Update 2**). You can replace `Environment.SpecialFolder.Windows` with `Environment.SpecialFolder.DesktopDirectory` to get the desktop instead. On my machine, they're the same date. – Rufus L Sep 30 '17 at 00:18
  • My C:\Windows creation date is 3/18/2017 again, months older then today when windows was installed. Environment.SpecialFolder.DesktopDirectory would definitely work - is there a way for me to loop through the desktops of all users in case the current user is not the oldest user? It would have to skip C:\Users\Public\Desktop since that is older then Windows install – Makanar Sep 30 '17 at 00:34
  • Wait, I though you were asking for the *very first time* windows was installed on this store-bought machine. Surely you're not suggesting that the Windows folder was there *before* windows was installed? Or maybe I'm misunderstanding what you're looking for. – Rufus L Sep 30 '17 at 00:41
  • Yes, the creation date of the Windows folder listed in file explorer is somehow 3/18/2017, older then when Windows was installed. I suspect it copies it from the iso rather then creating a fresh folder. However, using var createDate = Directory.GetCreationTime(Path.GetPathRoot( Environment.GetFolderPath(Environment.SpecialFolder.Windows))); gives mea different date somehow - 7/15/2016 11:04:24 PM - an date even older. – Makanar Sep 30 '17 at 00:56
  • The desktop directory seems to be the way to go though - I will post a separate question on how to loop through users excluding Default. default.migrated, all users, Public, etc to get the path of the oldest desktop directory, once I take a stab at it myself. Thanks for pointing me in the right direction! – Makanar Sep 30 '17 at 01:17