我正在使用一个在OS启动时启动的应用程序。有什么方法可以知道应用程序是从系统启动还是从手动执行启动?如何从Windows启动分析参数到.NET应用程序?
我目前的尝试(无效):
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("Low CPU Detector /fromStartup", Application.ExecutablePath.ToString());
然后我得到
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0 && args[0] == "fromStartup") {
doSomething()
}
(...)
我也看了这个How to detect whether application started from startup or started by user?,但它并没有帮助
你看到了什么行为?你应该记录你的args数组的值,以便你可以调试它。 – 2011-04-21 03:01:01
你的意思是'args [0] ==“/ fromStartup”'? – Gabe 2011-04-21 03:02:00