我设计了一个应用程序,当他打开电脑时应该问候用户。该程序在我的电脑上运行良好,但当我在我兄弟的计算机上传输程序的.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)
{
}
}
} `
答案 0 :(得分:0)
目标计算机应符合要求,至少应安装正确的.net版本和其他依赖项(如果有)。由于您正在写入注册表,因此可能需要管理员权限。 还有一件事。你真的不需要一个winforms应用程序。控制台应该做的。
答案 1 :(得分:0)
如果您希望在Windows启动后启动程序,请将可执行文件复制到启动目录:
以下是来源:http://windows.microsoft.com/en-gb/windows/run-program-automatically-windows-starts#1TC=windows-7。
如果程序未在您的朋友PC上运行,请确保.NET版本正确。事件查看器中可能有更多信息告诉您问题所在。