NEWS

[C# - VB.NET] Hướng dẫn tạo ứng dụng dùng thử Trial 30 day sử dụng phần mềm đóng gói Advance Installer 14.6

[C# - VB.NET] Hướng dẫn tạo ứng dụng dùng thử Trial 30 day sử dụng phần mềm đóng gói Advance Installer 14.6
Đăng bởi: Thảo Meo - Lượt xem: 16042 13:39:38, 18/09/2018DEVEXPRESS   In bài viết

Xin chào các bạn, bài viết hôm nay mình sẽ hướng dẫn các bạn cách đóng gói phần mềm dùng thử 30 ngày (số ngày các bạn có thể tùy chỉnh) sử dụng phần mềm Advance Installer.

[C# - VB.NET] Tutorial Create app trial 30 day using Advance Installer 14.6

Trong bài viết này mình sẽ dụng phiên bản Advance Installer 14.6, vì phiên bản này mình dùng được chức năng tạo Trial app của Advance Installer.

Các bạn có thể download phần mềm Advance Installer 14.6 ở link bên dưới để thực hiện.

[SOFTWARE] Download và cài đặt phần mềm đóng gói chuyên nghiệp Advance Intaller 14.6

1. Đầu tiên các bạn tạo một ứng dụng cơ bản như hình bên dưới:

Đóng gói phần mềm

2. Tiếp theo các bạn mở phần mềm Advance Installer lên, và import project của mình vào

tạo phần mềm dùng thử C#

3. Sau khi các bạn , next xong sẽ đến phần cài đặt license cho phần mềm, lưu ý bạn nào đến đây mà không tạo được Trial, thì cài phần mềm của mình có để link bên trên nhé.

Ở giao diện, bên dưới các bạn đặt tên Trial (tên này sẽ trùng với tên Trail.dll mà chút nữa mình import vào solution của mình)

- Ở phần Limit At: các bạn chọn số ngày (mặc định mình đang chọn là 30 ngày). 

- Ở phần platform các bạn chọn 32bit nhé, vì vậy lúc build phần mềm mình sẽ chọn x86 để thực hiện.

tạo phần mềm dùng thử vb.net

- Tiếp theo, các bạn qua tab Display và chọn cấu hình như mình ở hình bên dưới:

cấu hình phần mềm dùng thử 30 ngày vb.net

Ở hình này, mình chọn Display frequency percent là 100 nhé.

3. Tiếp theo các bạn chọn tab Registration, ở phần này các bạn sẽ nhập số key cần tạo và lưu file key này ra thư mục để sử dụng khi đăng ký phần mềm

tạo key phần mềm c#

4. Tiếp theo các bạn copy key như hình bên dưới và dán vào solution của bạn.

import key đóng gói

5. Tích hợp code chứng thực ứng dụng vào C#:

Source code C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
/*add references here :*/
using System.Runtime.InteropServices;
using System.Diagnostics;

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

        #region Trial Section :
        // This function does all the work
        [DllImport("TrialApp.dll", EntryPoint = "ReadSettingsStr", CharSet = CharSet.Ansi)]
        static extern uint InitTrial(String aKeyCode, IntPtr aHWnd);

        // Use this function to register the application when the application is running
        [DllImport("TrialApp.dll", EntryPoint = "DisplayRegistrationStr", CharSet = CharSet.Ansi)]
        static extern uint DisplayRegistration(String aKeyCode, IntPtr aHWnd);

        // The kLibraryKey is meant to prevent unauthorized use of the library.
        // Do not share this key. Replace this key with your own from Advanced Installer 
        // project > Licensing > Registration > Library Key
        private const string kLibraryKey = "2BFD80F5BEF59F563004D7FB548FC40C6C8DFED56684908FCB5F4FF332BC348E48D8E6AE91BD";

        private static void OnInit()
        {
            try
            {
                Process process = Process.GetCurrentProcess();
                InitTrial(kLibraryKey, process.MainWindowHandle);
            }
            catch (DllNotFoundException ex)
            {
                // Trial dll is missing close the application immediately.
                MessageBox.Show(ex.ToString());
                Process.GetCurrentProcess().Kill();
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.ToString());
            }
        }

        private void RegisterApp(object sender, EventArgs e)
        {
            try
            {
                Process process = Process.GetCurrentProcess();
                DisplayRegistration(kLibraryKey, process.MainWindowHandle);
            }
            catch (DllNotFoundException ex)
            {
                // Trial dll is missing close the application immediately.
                MessageBox.Show(ex.ToString());
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.ToString());
            }
        }
        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            OnInit();
        }
    }
}

- Nếu bạn nào sử dụng VB.NET thì cấu hình source code VB.NET như bên dưới:

Imports System
Imports System.Runtime.InteropServices
...

' This function does all the work
<DllImport("Trial.dll", EntryPoint:="ReadSettingsStr", CharSet:=CharSet.Ansi)> _
Private Shared Function InitTrial(ByVal aKeyCode As String, ByVal aHWnd As IntPtr) As UInteger
End Function


' Use this function to register the application when the application is running
<DllImport("Trial.dll", EntryPoint:="DisplayRegistrationStr", CharSet:=CharSet.Ansi)> _
Private Shared Function DisplayRegistration(ByVal aKeyCode As String, ByVal aHWnd As IntPtr) As UInteger
End Function


' The kLibraryKey is meant to prevent unauthorized use of the library.
' Do not share this key. Replace this key with your own from Advanced Installer
' project > Licensing > Registration > Library Key
Private Shared kLibraryKey As String = "3F76246B3B0E194506CBC8F512D70B9D0EF8242CEFA92E03237D7152AF70DBD428ED559FBB90"

' The register state of the application which is computed when the form is loaded
Private registered As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  Try
    Dim Proc As Process = Process.GetCurrentProcess()
    ' This call will display the trial dialogs if needed
    Dim ret = InitTrial(kLibraryKey, Proc.MainWindowHandle)

    ' 0 return code means that the application is registered using a valid code, otherwise is in trial
    If ret = 0 Then
      registered = True
    End If

  Catch ex As Exception
    MessageBox.Show(ex.ToString())
    Process.GetCurrentProcess().Kill()
  End Try

End Sub

Private Sub DoRegister()
  Try
    Dim Proc As Process = Process.GetCurrentProcess()
    Dim ret = DisplayRegistration(kLibraryKey, Proc.MainWindowHandle)

    ' 0 return code means that the application was already registered or it
    ' has just been registered, otherwise is in trial
    If ret = 0 Then
      registered = True
    End If

  Catch ex As Exception
    MessageBox.Show(ex.ToString())
    Close()
  End Try
End Sub

Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
  Dim dlg As AboutBox1 = New AboutBox1

  ' Set the about box member to the registered state computed when the application loaded
  dlg.registered = Me.registered

  ' Display the  About box
  dlg.Show()
End Sub

Private Sub RegisterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegisterToolStripMenuItem.Click
  If registered Then
    MessageBox.Show("The application is already registered.", "Registered", MessageBoxButtons.OK, MessageBoxIcon.Information)
  Else
    DoRegister()
  End If
End Sub
        
Into the AboutBox1.vb source file add the following code snippets:

...
Public registered As Boolean
Private Sub AboutBox1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  ...
  If Me.registered Then
    Me.TextBoxDescription.Text = "registered - thank you"
  Else
    Me.TextBoxDescription.Text = "trial"
  End If
End Sub

- Đến bước này là xong, các bạn có thể build ứng dụng, và dưới đây là kết quả khi các bạn chạy file cài đặt:

đóng gói phần mềm vb.net

- Ở mục này, các bạn chọn Try thì sẽ dùng thử và nếu bấm vào nút Register thì nhập key mà lúc nãy mình tạo ra ở bước trên để đăng ký.

* Lưu ý: khi các bạn đăng ký key, thì key sẽ được lưu ở Regedit Windows ở đường dẫn: Current UserSoftwareYour CompanyYour ProductRegistration Key 

+ Video hướng dẫn từng bước thực hiện đóng gói phần mềm dùng thử bằng C#:

Mọi thắc mắc, các bạn có thể để lại comment bên dưới, để được support.

HAPPY CODING heart

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C# - VB.NET] Hướng dẫn tạo ứng dụng dùng thử Trial 30 day sử dụng phần mềm đóng gói Advance Installer 14.6
Đăng bởi: Thảo Meo - Lượt xem: 16042 13:39:38, 18/09/2018DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.