Install ClickOnce without running

爱⌒轻易说出口 提交于 2019-11-28 01:02:54

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.

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.

Magnus Johansson

To disable the automatic start after install, you simply disable the URL activation as discussed in the MSDN article How to: Disable URL Activation of ClickOnce Applications (using the tool MageUI.exe).

To disable URL activation for your application

  • Select the Deployment Options tab.

  • Clear the Automatically run application after installing check box.

  • Save and sign the manifest.

John Hunter

You can do this by editing the application manifest in Mage. There is a checkbox to stop the application running after installation.

If you are not comfortable editing a manifest manually or with Mage then you can use the built-in deployment class to check whether this is the first time the application has run.

using System.Deployment.Application

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

    if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
    {
        MessageBox.Show("Install Complete");
        return;
    }

    Application.Run(new Form1());
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!