简体   繁体   English

在Windows启动时启动应用程序

[英]Start application at when windows Starts

I have checked some other examples. 我查了一些其他的例子。

I am working on a winfrom. 我正在努力争取胜利。 & now i am going to create its installer. 现在我要创建它的安装程序。

i want to start the software when windows starts & trying to use the following code. 我想在Windows启动并尝试使用以下代码时启动该软件。

RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());

But i am confused that where to put this code. 但我很困惑,在哪里放这个代码。 i don't want this code executed every time when my application starts as it will executed once when the software is installed. 我不希望每次应用程序启动时执行此代码,因为它将在安装软件时执行一次。

shall i put check on form_Load() if the regkey is absent, & if yes then add this value to the Run. 如果没有regkey,我应该检查form_Load(),如果是,则将此值添加到Run。

is it correct ? 这是正确的吗 ? i don't want to give an option to the user & i want to start this application at the startup compulsorily. 我不想给用户一个选项,我想在启动时强制启动这个应用程序。

Thanks. 谢谢。

As the others users have commented, this kind of thing should go on the installer. 正如其他用户评论的那样,这种事情应该继续安装。 On the setup project you can create with Visual Studio, you can add a link to the user's startup folder that should do the trick. 在您可以使用Visual Studio创建的安装项目中,您可以添加指向应该执行操作的用户启动文件夹的链接。

BUT

If you don't want the user tampering with the startup folder and you absolutely want the program to start automagically with Windows, you could do as you've said: check for the adequate registry key everytime the program starts, and if it's not there write it. 如果您不希望用户篡改启动文件夹并且您绝对希望程序能够自动启动Windows,您可以按照您的说法执行操作:每次程序启动时检查是否有足够的注册表项,如果它不存在写下来。 Take into account your program will need elevated account rights for this. 考虑到您的程序需要提升帐户权限。

BUT

Do you ABSOLUTELY need this? 你绝对需要这个吗? Are you absolutely sure you can't offer it as an option to the final user? 您是否绝对确定不能将其作为最终用户的选项提供? If I was a user to your program, didn't want it on startup, take the effort to remove a registry key to get it out of there and then find out it's again in the registry without my consent, I'd be pretty pissed... 如果我是您的程序的用户,在启动时不想要它,请努力删除注册表项以将其从那里取出然后在未经我同意的情况下再次在注册表中找到它,我会非常生气...

You can create your customAction class for your installer like this: http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx#Y0 您可以为安装程序创建customAction类,如下所示: http//msdn.microsoft.com/en-us/library/d9k65z2d.aspx#Y0

Once you have this class, put your registry code in the commit section. 拥有此类后,将注册表代码放在提交部分中。 Now, whenever your application will be installed, your application will be added to registry to run at startup. 现在,无论何时安装您的应用程序,您的应用程序都将添加到注册表中以便在启动时运行。

创建一个使用该行的小型控制台应用程序,并在安装结束时运行该应用程序。

It depends on the istaller software that you use. 这取决于您使用的istaller软件。 If you use the setup project template provided by Visual Studio, you can have the registry key created automatically . 如果使用Visual Studio提供的安装项目模板 ,则可以自动创建注册表项

Your installer should create the registry keys. 您的安装程序应该创建注册表项。

In addition, your installer may also ask whether to install for the current user or for all users. 此外,您的安装程序还可能会询问是为当前用户还是为所有用户安装。 If user says everyone, then the key must be added in HKEY_LOCAL_MACHINE rather than HKEY_CURRENT_USER , which requires admin privileges. 如果用户说每个人,则必须在HKEY_LOCAL_MACHINE而不是HKEY_CURRENT_USER添加密钥,这需要管理员权限。 Installers do usually have that privilege . 安装人员通常拥有这种特权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 强制Winforms安装使应用程序在Windows启动时启动 - Forcing Winforms install to make application to start when windows starts 我们启动电脑时如何启动windows应用程序 - How to start the windows application when we starts the computer 在Windows Shell启动之前启动应用程序? - Start Application Before Windows Shell Starts Up? 当Windows启动时,如何使我们的表单(应用程序)开始运行? - How to make our form(application) start running when windows starts in C#? 如何在Windows Mobile中启动设备时启动应用程序? - How do you make an application start when the device starts up in Windows Mobile? 是否有可能知道应用程序何时在Windows Phone 7中启动? - Is it possible to know when application starts in windows phone 7? 在应用程序启动之前启动 procdump? - Start procdump before application starts? Windows启动时停止应用程序服务 - Stop service of Application When Windows Start 在Visual Studio上启动.NET MVC应用程序时启动ac#控制台应用程序 - Start a c# console application when .NET MVC Application starts on Visual Studio 您可以将IIS7配置为在启动/回收应用程序池时自动启动Windows进程激活服务(WAS)应用程序吗? - Can you configure IIS7 to autostart a Windows Process Activation Service (WAS) application when the application pool starts/recycles?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM