Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I create a registry file in C Sharp Windows Application. In this file I want to store last execution date & read this date when next execution for compare the last execution date from registry & current System date. If is it possible to hide this registry file.
Posted

1 solution

try this Code :)
DateTime GetLastExecutionDate()
        {
            RegistryKey rkey = Registry.CurrentUser;
            RegistryKey rkey1 = rkey.OpenSubKey("software", true);
            RegistryKey rkey2 = rkey1.CreateSubKey("tes");
            DateTime lastDate = DateTime.Parse(rkey2.GetValue("LastDate").ToString());
            return lastDate;
        }
        void AddLastExecutionDate()
        {
            RegistryKey rkey = Registry.CurrentUser;
            RegistryKey rkey1 = rkey.OpenSubKey("software", true);
            RegistryKey rkey2 = rkey1.CreateSubKey("tes");
            rkey2.SetValue("LastDate", DateTime.Now.ToShortDateString());
        }

this link will help for registry operations
Read, write and delete from registry with C#[^]
 
Share this answer
 
v2
Comments
Member 7891405 3-May-11 8:23am    
i want to add new date in registry in same file that time "Cannot write to the registry key." error occures
ambarishtv 3-May-11 8:59am    
this code run in xp and vista,
I think you've no permission for writing a registry file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900