Stop the installation from a custom action

2019-06-07 18:07发布

Is it possible to exit msi installar from a custom action without errors?

I am using visual studio setup project to create the msi and I have added a custom action exe to install. If I return a value other than 0 from exe it terminate the installation. But it shows an error. I need to exit installation without showing errors.

Thanks.

2条回答
Fickle 薄情
2楼-- · 2019-06-07 18:15

Try this code in your installer class. I hope it will resolve your problem.

protected override void OnBeforeInstall(IDictionary savedState)
        {
            if (LaunchOnBeforeInstall())
            {
                base.OnBeforeInstall(savedState);
            }
            else
            {
                throw new Exception("You cancelled installation");
            }
        }
        public bool LaunchOnBeforeInstall()
        {
            Form2 frm2 = new Form2();
            DialogResult result = frm2.ShowDialog();
            if (result == DialogResult.Cancel)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

And also put "NOTPREVIOUSVERSIONSINSTALLED"

enter image description here

查看更多
贼婆χ
3楼-- · 2019-06-07 18:22

Finally I found a way to do it using a vbscript custom action from http://chensuping.blogspot.com/2013/05/windows-setup-project-vbs-custom-action.html.

查看更多
登录 后发表回答