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
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);
}