Search code examples
c#registry

Using C# fetch Registered time of file (dll,exe,ocx)


I am installing an application, post installation i am performing few verification. One of which is to check the registered time and other is to check if the expected files list is registered.

I have list of files which should get registered and i have written code to verify that. But somehow i am not able to find a way to get the registered time[Date and Time] of the registered file.

Below is the code i wrote for fetching complete list of registry file and then run a loop of expected files on the obtained files to check if they are present or not.

static void Main(string[] args)
{

    string keyPath = @"SOFTWARE\Classes";
    //string keyPath = "InprocServer32";

    RegistryKey topRegKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default).OpenSubKey(keyPath);

    GetAllKeys(topRegKey);
    int b = result.FindIndex(p => p.ToLower().Contains("MSCOMCT2.OCX".ToLower()));
}

public List<string> RegKeysList = new List<string>();

public static void GetAllKeys(RegistryKey regKey)
{
    if (regKey != null)
    {
        foreach (string key in regKey.GetSubKeyNames())
        {
            GetAllKeys(regKey.OpenSubKey(key));
        }
        if (regKey.GetSubKeyNames().Length == 0)
        {
            try
            {
                result.Add(regKey.GetValue(string.Empty).ToString());
            }
            catch (Exception)
            {

            }
        }
    }

}

I was able to find a C++ function RegQueryInfoKey function - ftLastWriteTime to perform it(Didn't explore more on this). But i want to keep that as my last option.

Is there a way using C# to perform this. Am i missing something?


Solution

  • I ran RegDllView through command prompt and generated a file with all registered files using C#. Which had all registered files list with version,date,etc.

    Through C# i copied RegDllView.exe to my server machine.

    Followed by fetching required files list from the file. PFB working code:

    System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = "/C " + RegDllViewExePath + " /scomma " + RegDllOutputFilePath;
                process.StartInfo = startInfo;
                process.Start();