Question

I have an application that uses ClickOnce to deploy, and I have managed to get the application starting when a user logs in.

My issues are that I need the application to start up hidden (I don't want a user to have to minimize it until they require it - I want it to sit in the system tray). Prior to using ClickOnce I simply checked the arguments to see if "/silent" was passed in. There appears to be no way to do this in a ClickOnce application (you can check if a URI query string is passed in, but because this is run from a .appref-ms shortcut there appears to be no way to get the /silent argument)

How can I get the /silent argument, or how can I tell if the application has started as a result of the user logging on (rather than the user starting the application from a shortcut)?

It is important that whatever solution proposed doesn't require administrator permissions, but the language used isn't as important as I can probably port it to .NET.

Was it helpful?

Solution

I don't think there's a very clean way to do this since command arguments don't work, and you can't use query string arguments.

However, try deploying another small executable with your ClickOnce deployment. It would be responsible for setting a "startup" flag (in a configuration file, registry, whatever) and then launching your actual application. Your application would check the flag to determine if it should launch silently and then reset the flag. Then you would just have the small executable start with Windows rather than your main application.

Of course I didn't try any of this out.

OTHER TIPS

You can do it this way:

In your Main-method:

if ((args.Length > 0 && args[0].ToLower() == "minimized") ||
    (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0 &&
    AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0] == "minimized"))//ClickOnce arguments
{

    //My code to start minimized. My system tray is always visible
    main.WindowState = FormWindowState.Minimized;
    main.Hide();
    main.ShowInTaskbar = false;
}
else {

    //Code to start normally
    main.WindowState = FormWindowState.Normal;
    main.ShowInTaskbar = true;
    main.Show();
}

Then you can just pass the argument 'minimized' with the ClickOnce-application to start it minimized.

To start my ClickOnce application automatically, I make a shortcut like this:

CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + @"\LVH Tools\MyMiniTools.appref-ms", Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\MyMiniTools", "minimized")

'MyMiniTools' is the name of the application, and 'LVH Tools' is the Publisher name.

CreateShortcut:

    public void CreateShortcut(string destinationPath, string shortcutPath, string arguments = "")
    {
        IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

        shortcutPath = Path.ChangeExtension(shortcutPath, "lnk");

        IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);

        shortcut.TargetPath = destinationPath;
        shortcut.IconLocation = destinationPath;
        shortcut.Arguments = arguments;

        shortcut.Description = Path.GetFileNameWithoutExtension(destinationPath);

        shortcut.Save();
    }

Another method to enable autostart with ClickOnce is explained in ClickOnce application autostart and clean uninstall or the way to customize ClickOnce installation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top