程序从Windows启动吗?C# [英] Program start with windows? c#

查看:53
本文介绍了程序从Windows启动吗?C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以

我已经建立了一个winform,可以打开一个新程序.

i have builed a winforms that just open a new program.

winform中的代码是这样的:(如果有人需要的话)

The code that is in the winform is this:(if anyone needs)

Process a;

Process a = Process.Start("notepad.exe");

但是.

我需要知道如何与Windows Startup一起启动该程序.像Skype一样,或其他任何程序.

i need to know how can i say to the program to start with Windows Start up. Like skype do, or any other program.

所以

  1. 我构建了一个winforms应用程序.
  2. 我做了一个开始过程.
  3. 现在我需要帮助以使该程序与Windows配合使用.

唯一重要的是,该程序将允许我选择是否要她从Windows开始.因此,如果有人给我功能,请给我开/关功能.谢谢分配!

The only important thing, is that the program will allow me to chose i want her to start with windows or not. so, if anyone give me functions, please, give me on\off functions. THANKS ALLOT!

推荐答案

如果要在Windows启动时自动启动应用程序,则必须在Windows注册表中注册它.

If you want to automatically start an application on Windows startup you must register it in the Windows Registry.

您需要将新值添加到以下注册表项:

You need to add a new value to the following registry key:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

这将为当前用户启动应用程序

which will start the application for the current user

或键

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 

这将为所有用户启动该应用程序

which starts the application for all users

以下示例将为当前用户启动应用程序:

The following example will start 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.

如果要禁用此功能,以使应用程序不会自动启动,只需删除注册表值即可.

If you want to disable this so that the application won't start automatically, just remove the registry value.

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

这篇关于程序从Windows启动吗?C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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