设置安装文件的密码 [英] Set Password for Setup file

查看:94
本文介绍了设置安装文件的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的vb.net软件创建安装文件.安装安装文件时,我想设置密码.此密码应该是动态的.怎么做 ?如果有人知道,请帮助我.

I am creating Setup file for my vb.net software. I want to Set password, when I install the setup file. This password is should be dynamic. How to do it ? If anybody knows, please help me.

推荐答案

在这种情况下,您可以使用自定义操作.
1.将Installer类添加到项目中.
2.创建一个表单,让用户输入密码. FrmPassword的代码如下.
You can use custom action in this case.
1. Add an Installer class to the project.
2. Create a form to let the user input password. The code of the FrmPassword is as follow.
public partial class FrmPassword : Form
    {
        private Installer1 install;
        public FrmPassword(Installer1 installer)
        {
            InitializeComponent();
            this.install = installer;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "12345")
            {
                MessageBox.Show("Password incorrect!");
                install.isValid = false;
            }
            else
            {
                install.isValid = true;
            }
            this.Close();
        }
    }
//Override the OnBeforeInstall method like this.
[RunInstaller(true)]
    public partial class Installer1 : Installer
    {
        public bool isValid = false;
        public Installer1()
        {
            InitializeComponent();
        }
        protected override void OnBeforeInstall(IDictionary savedState)
        {
            FrmPassword frm = new FrmPassword(this);
            frm.ShowDialog();
            if (this.isValid == false)
            {
                throw new Exception("Force to rollback!");
            }
            base.OnBeforeInstall(savedState);
        }
    }


isValid成员将记住输入的密码是否正确.密码正确时,FrmPassword会将isValid设置为True.如果isValid为false,则安装程序类将抛出错误强制回滚.


The isValid member will remember if the input password is correct. When the password is correct, FrmPassword will set the isValid to True. If the isValid is false, the installer class will throw an error force to rollback.


这篇关于设置安装文件的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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