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

2020-01-30 06:19发布

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 shortcut would be placed in the Startup folder, but that seems like a huge hack and I would like there to be a Start menu icon people can find.

What options do I have?

11条回答
Summer. ? 凉城
2楼-- · 2020-01-30 06:48

First off thanks for the answer Discdev. To get this to work with Å Ä Ö and other special characters this modification did it for me, using UTF-8 a different code page and no BOM.

string[] mystrings = new string[] { "chcp 65001", @"IF EXIST ""%appdata%\Microsoft\Windows\Start Menu\Programs\<Publisher>\<App_Name>.appref-ms"" (""%appdata%\Microsoft\Windows\Start Menu\Programs\<Publisher>\<App_Name>.appref-ms"") ELSE (start /b """" cmd /c del ""%~f0""&exit /b)" };
string fullPath = "%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\StartErrandDynamicMenu.bat";
System.Text.Encoding utf8WithoutBOM = new System.Text.UTF8Encoding(false);
System.IO.File.WriteAllLines(Environment.ExpandEnvironmentVariables(fullPath), mystrings, utf8WithoutBOM);
查看更多
家丑人穷心不美
3楼-- · 2020-01-30 06:48

In terms of actually getting the application to launch at startup, having a link in the startup folder is your best bet. Or if not the startup folder then the startup reg key.

A way to work around not having the Icon in it's normal position is to have the application place a link to itself into the startup folder on Application startup. ClickOnce apps will run the first time they are installed. The application can use this startup to place a link in the Startup folder. Now the link will be in both places and you should be golden.

There is the issue though that now deleting the ClickOnce app will no longer actually delete it. ClickOnce will not track the manual link added and hence every time someone un-installs your app and reboots it will re-install. I would start considering that program to not be behaving well :(.

查看更多
爷的心禁止访问
4楼-- · 2020-01-30 06:48

In case it helps anyone else still looking for a solution to this a comment way down the bottom http://johnnycoder.com/blog/2009/02/24/clickonce-run-at-startup/ suggests setting the ClickOnce Publish options (in VS.Net 2010 that's on the project properties, publish screen and options) with Publisher name set to Startup and Suite name left blank. That does get the program shortcut into the startup folder for me on Windows 7. I don't know what other versions of Windows do.

查看更多
干净又极端
5楼-- · 2020-01-30 06:50

All these tricks dont work on Vista unfortunately. Vista blocks these programs on startup for some reason.

As suggested by @thijs, you can easily bypass vista's "security" on this one. See blogpost on how to run clickonce apps on windows startup.

查看更多
Melony?
6楼-- · 2020-01-30 06:52

You could add your app to the appropriate "Run" startup registry key at startup. Then even though you can't remove it when your app is deleted, it won't hurt anything and nobody will see the broken reference.

查看更多
登录 后发表回答