简体   繁体   English

我如何“约会”保护我的申请?

[英]How do I “date-protect” my application?

I've built a little WindowsForm app from a standard beginner's tutorial. 我从标准的初学者教程中构建了一个小的WindowsForm应用程序。 The kind where you use controls like buttons and textboxes to add 2 numbers and have the result show up in a textbox. 您使用按钮和文本框等控件添加2个数字并将结果显示在文本框中的类型。

Anyways, I want to make it so that when a user clicks on my .exe, it checks against my built-in expiration date before even launching the program/window. 无论如何,我想这样做,以便当用户点击我的.exe时,它会在启动程序/窗口之前检查我的内置过期日期。 That is, if my expiration date were today Oct. 30, nothing happens, no window form even shows up. 也就是说,如果我的失效日期是今天10月30日,那么没有任何事情发生,甚至没有窗口形式出现。 However, if my expiration date were to be Oct. 31, everything proceeds normally and windows and forms show up. 但是,如果我的到期日期是10月31日,那么一切都会正常进行,窗口和表格会显示出来。 But, tomorrow on Oct. 31 (expiration date) and any day after tomorrow if the user were to run my .exe, nothing would happen. 但是,明天10月31日(到期日)和明天任何一天如果用户运行我的.exe,都不会发生任何事情。

I think my code would look something like this: 我认为我的代码看起来像这样:

DateTime expiration = new DateTime(2013, 10, 31) //Oct. 31, 2013
If (DateTime.Today < expiration) //proceed normally
else // do nothing, nothing happens for the user

From the tutorial, most of my understanding is confined to code written inside the public Form1 : Form part of the code: 从教程中,我的大部分理解仅限于在公共Form1中编写的代码:表单代码的一部分:

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}

Where would I insert code to check today's date against my expiration date so that no forms are loaded? 我会在哪里插入代码来检查今天的日期与我的到期日期,以便不加载任何表格?

Look at Program.cs in your Solution Explorer. 查看解决方案资源管理器中的Program.cs You can add this code inside the Main function, and call Application.Exit() to leave the application if the condition you have specified hasn't been met. 您可以在Main函数中添加此代码,如果未满足您指定的条件,则调用Application.Exit()以退出应用程序。

I won't recommend using "Local Time" for this because user can take the freedom of changing it anytime. 我不建议使用“本地时间”,因为用户可以随时自由地更改它。

Probably you'll have to get current time from some "Time server" 可能你必须从一些“时间服务器”获得当前时间

private static readonly DateTime expiration = new DateTime(2013, 10, 31);
static void Main()
{
    DateTime currentTime = GetTimeFromSomeTimeServer();//Implement yourself
    if (currentTime.Date >= expiration.Date)
    {
        return;//Dont run the app
    }
    //Rest of your code...
}

You most likely want this in the Program.cs file, here's a simple example 你很可能在Program.cs文件中想要这个,这是一个简单的例子

static class Program
{
    static DateTime expiration = new DateTime(2013, 10, 31);

    /// <summary>
    /// The main entry point for the application
    /// </summary>
    [STAThread]
    static void Main()
    {
        if (DateTime.Today < expiration.Date) 
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        else
        {
            Application.Exit();
        }
    }
}

However, just bare in mind that this isn't really the recommended approach for enforcing an expirable application (eg trial software). 但是,请记住,这并不是实施可过期应用程序(例如试用软件)的推荐方法。 Generally it's better to use some form of robust licensing system, hard-coding the date into the exe is by no means full-proof and easily exploitable. 通常,最好使用某种形式的强大许可系统,将日期硬编码到exe中并不是完全可靠且易于利用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何保护我的 .net 应用程序免受反编译器的攻击? - How can i protect my .net application from decompilers? 如何保护我的注册/注册 API - How do I protect my signup/ registration apis 如何吞下所有异常并保护我的应用程序不会崩溃? - How can I swallow all exceptions and protect my application from crashing? 我可以使用 AOT 编译来保护我的应用程序吗? - Can I protect my application using AOT compilation? 如何从C#应用程序中获取要在我的SQL数据库上运行的SELECT日期查询? - How do I get a SELECT date query to run on my SQL database from C# application? 如何保护我的 C# 应用程序免受 memory 转储攻击? - How do I protect my C# app from memory dump attack? 在非托管DLL中调用方法时,如何保护C#应用程序免于崩溃? - How do I protect my C# app from crashing when calling a method in an unmanaged DLL? 如何保护用户反编译项目的OAuth密钥? - How do I protect OAuth keys from a user decompiling my project? 如何保护将重要数据发布到我的数据库的公共 ASMX 页面 - How do I protect a public ASMX page that posts important data to my database 如何保护Web应用程序 - How to protect a Web Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM