How can I make a Click-once deployed app run at startup?

后端 未结 11 1745

How can I make a Click-once deployed app run a startup?

The best option I found by searching was to set the Publisher on the app to Startup, so the Start menu shortc

11条回答
  •  北海茫月
    2020-12-04 22:58

    Thanks DiscDev and dbenham. The solution works great. Just wanted to share the updated working code based on the latest by dbenham.

     const string fullPathEnvVar =
                "%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\StartMyClickOnceApp.bat";
     //Expands the %appdata% path
     string fullPath = Environment.ExpandEnvironmentVariables(fullPathEnvVar);
    
    if (!File.Exists(fullPath))
            {
                string[] mystrings =
                {
                    @"@echo off 
    if exist ""%appdata%\Microsoft\Windows\Start Menu\Programs\\.appref-ms"" (
    ""%appdata%\Microsoft\Windows\Start Menu\Programs\\.appref-ms""
    ) else (
    (goto) 2>nul & del ""%~f0""
    )"
                };
                //write the file to the Startup folder
                File.WriteAllLines(fullPath, mystrings);
            }
    

提交回复
热议问题