在Windows启动时启动窗口 [英] Launch Window on Windows startup

查看:220
本文介绍了在Windows启动时启动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序(一个WPF 窗口),在Windows启动时启动。我想尽了各种办法,但似乎没有人上班。我有我的代码写的做到这一点?

I want that my application (a WPF Window) is launched on Windows startup. I tried different solutions, but no one seems to work. What i have to write in my code to do this?

推荐答案

当你说你必须添加一个关键看你是正确的。注册表

You are correct when you say that you must add a key to the registry.

添加一键:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

如果您想启动应用程序

Or:

或\\Microsoft\Windows\CurrentVersion\Run

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

如果你想要启动它为所有用户。

If you want to start it for all users.

例如,从当前用户的应用程序:

For example, starting the application for the current user:

var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
key.SetValue("MyApplication", Application.ExecutablePath.ToString());

只需要用

RegistryKey key = Registry.LocalMachine.OpenSubKey(path, true);

如果你想自动启动在Windows启动时所有用户的应用程序。

if you want to automatically start the application for all users on Windows startup.

只是删除注册表值,如果您不再希望自动启动的应用程序

Just remove the registry value if you no longer want to start the application automatically.

这样:

var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
key.DeleteValue("MyApplication", false);

此示例代码是为WinForms应用程序进行测试。如果您需要确定可执行文件路径为一个WPF应用程序,然后给一个尝试以下。

This sample code was tested for a WinForms app. If you need to determine the path to the executable for a WPF app, then give the following a try.

string path = System.Reflection.Assembly.GetExecutingAssembly().Location;



只需更换Application.ExecutablePath.ToString()的路径可执行文件。

Just replace "Application.ExecutablePath.ToString()" with the path to your executable.

这篇关于在Windows启动时启动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆