在不运行的情况下安装 ClickOnce

编程入门 行业动态 更新时间:2024-10-21 11:42:13
本文介绍了在不运行的情况下安装 ClickOnce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装 ClickOnce 应用程序时,该程序会在安装后运行.是否可以在不运行的情况下安装?

When you install a ClickOnce application, the program runs after the install. Is it possible to install without running?

我知道我可以使用设置和部署项目并创建安装程序,但我更喜欢使用 ClickOnce.

I know I can use a setup and deployment project and create an installer, but I'd prefer to use ClickOnce.

推荐答案

我猜你可以伪造它.引入IsInstalled"布尔属性,默认为 false.然后在 Program.cs 中,将 Main() 方法更改为如下所示:

I guess you could fake it. Introduce an "IsInstalled" boolean property, defaulted to false. Then in Program.cs, change your Main() method to look like this:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    if (!Properties.Settings.Default.IsInstalled)
    {
        Properties.Settings.Default.IsInstalled = true;
        Properties.Settings.Default.Save();

        MessageBox.Show("Install Complete");
        return;
    }

    Application.Run(new Form1());
}

所以现在当应用程序首次安装时,它会检查该属性并简单地向用户显示一条消息,然后退出.

So now when the app is first installed, it checks that property and simply displays a message to the user and then quits.

如果您想变得棘手,那么您可以查看解析部署的激活 URI,并使用 URI 参数指定程序是在首次安装时运行还是静默关闭.

If you wanted to get tricky then you could look at parsing the Activation URI for the deployment and have a URI parameter which specifies whether the program should run when it's first installed or just close silently.

这篇关于在不运行的情况下安装 ClickOnce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 03:20:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/794917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   ClickOnce

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!