将过期添加到C#windows应用程序 [英] Add expiration to C# windows application

查看:79
本文介绍了将过期添加到C#windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i我试图让make app在使用注册表选项几天后过期,我已成功写入并从注册表中读取,我的问题是检查到期,从我的代码我假设用户的第一次运行是04/16/2017,我还假设我希望用户运行应用程序一天,它应该在2017年4月17日到期,这意味着用户尝试在04/17/2017之后启动应用程序if部分应该执行,但我并没有真正做到正确,其他部分总是执行,我将欣赏更好的方法。谢谢



我尝试过:



Hello everyone,

i am trying to make make app expire after some days using the registry option, i have successfully written and read from registry, my issue is to check for expiration, from my code i assumed the user's first run is the 04/16/2017, i also assumed i want the user to run the application for one day, which supposed to expire on the 04/17/2017, meaning if the user tries to start the application after 04/17/2017 the if part should execute, but i am not really getting it right, the else part always execute, i will appreciate a better way of doing it. Thanks

What I have tried:

<pre>regKey = Registry.CurrentUser.OpenSubKey("Systemfiles");//subkeyname
            if (regKey == null)
            {
                regKey = Registry.CurrentUser.CreateSubKey("Systemfiles");
                regKey.SetValue("tere", Encrypt("4/16/2017"));
            }
            else
            {
                regKey = Registry.CurrentUser.OpenSubKey("Systemfiles");//subkeyname
                string decryptDateValue = Decrypt(regKey.GetValue("tere").ToString());  //Keyname
                DateTime mainDate = Convert.ToDateTime(decryptDateValue);

                DateTime expiringDate = mainDate.AddDays(1);
                if (mainDate > expiringDate)
                {
                    expire = true;
                }
                else
                {
                    //Continue execution
                }
            }

推荐答案

阅读你的指示:

Read your instructions:
DateTime expiringDate = mainDate.AddDays(1);
if (mainDate > expiringDate)

它始终为false因为 expiringDate = mainDate + 1天



您必须比较 expiringDate 使用当前日期:

It is always false because expiringDate = mainDate + 1 day.

You have to compare expiringDate with the current date:

if (DateTime.Now() > expiringDate)


这篇关于将过期添加到C#windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆