当电脑启动时自动运行程序
问题描述:
我设计了一个应用程序,当他打开他的电脑时应该问候用户。该程序在我的电脑上运行良好,但是当我将该程序的.exe文件转移到我兄弟的电脑上时,不起作用,这意味着“它不能自动工作时,电脑启动”...我怎样才能克服这个问题??这是我的代码当电脑启动时自动运行程序
注意:程序运行良好,如果我手动执行它,但我希望它自动工作。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
namespace helloMSG
{
public partial class Form1 : Form
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public Form1()
{
InitializeComponent();
reg.SetValue("My app", Application.ExecutablePath.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
} `
答
答
如果你想程序启动Windows启动后,则executeable复制到启动目录:
- 单击开始按钮开始按钮的图片,单击所有程序,用鼠标右键单击启动文件夹,然后单击打开。
- 打开包含要创建快捷方式的项目的位置。
- 用鼠标右键单击该项目,然后单击创建快捷方式。新的快捷方式出现在原始项目的相同位置。
- 将快捷方式拖入启动文件夹。
这里是信息来源:http://windows.microsoft.com/en-gb/windows/run-program-automatically-windows-starts#1TC=windows-7。
如果该程序无法在您的朋友PC上运行,请确保.NET版本正确。事件查看器中可能有更多信息告诉你问题是什么。
该程序是否可以在你兄弟的PC上运行?他安装了哪个版本的.Net? – 2014-10-04 08:49:37
迎接用户的程序在哪里?你有的代码似乎与阅读注册表有关! – 2014-10-04 08:52:02
该程序运行良好,如果我手动执行它,但我希望它自动工作。 – Boulis 2014-10-04 08:52:03