要用C#程序实现,谢谢各位指教!
解决方案 »
- caf格式转换成mp3
- C#实现电脑定时开关机的源码
- 讨论下多线程中的CheckForIllegalCrossThreadCalls是否安全
- 水晶报表报错
- winform 动态生成控件,取值和赋值问题。
- C# 为什么不能让 所有的对象自动回收它所使用的内存or资源
- 多个数据源怎么共用一个GridView分页??谢谢
- 这种实例化代码为什么不同?
- 使用WebRequest如何得到带有<META HTTP-EQUIV="refresh" content="10; url=xxxxxxx.asp">的网页执行后的内容?
- 问一个关于dataset合并的问题
- ADO.NET的问题
- 我想做一个远程下载的程序,不知该如何做,请高手帮忙?
这里是windows服务的写法。学习一下就搞定了。
服务也可以,但相比麻烦了点。
----------------------------------------------------
一样的,试一下就知道了。
如果是带Form的程序就不能用服务启动了,只能写进注册表。
我正要写一个这样的程序,不过我有一点不明白,为什么带Form的程序就不能用服务启动了,只能写进注册表?
/// <summary>
/// 作成者:jickie阿文 作成日時:2006/11/08
/// 処理内容:Applicationの自起動功能を追加します。
/// </summary>
private void SetRegistry()
{
try
{
string strAssName=Application.StartupPath+@"\"+Application.ProductName+@".exe";
string ShortFileName=Application.ProductName;
//
RegistryKey rgkRun=Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true);
if(rgkRun==null)
{//
rgkRun=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
else
{
rgkRun.SetValue(ShortFileName,strAssName);
}
}
catch{}
}
/// <summary>
/// 作成者:jickie阿文 作成日時:2006/11/22
/// 処理内容:Applicationの自起動功能を追加します。
/// </summary>
private void AddToStartUp()
{
try
{
DirectoryInfo dire=new DirectoryInfo(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup));
if(File.Exists(dire.FullName+@"\"+Application.ProductName+@".lnk"))
{
File.Delete(dire.FullName+@"\"+Application.ProductName+@".lnk");
}
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(dire.FullName+@"\"+Application.ProductName+@".lnk");
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
shortcut.WindowStyle = 7;
shortcut.Description = this.Text;
shortcut.Save();
}
catch{}
}
1、将程序作成Windows服务,如果想减少人为的干扰,这种是比较好选择。只要你能写Windows服务程序,服务是自动或手动启动很简单的。
2、如果是程序,修改注册表项也是比较好的,简单代码如下:
private void button1_Click(object sender, EventArgs e)
{
string FullPathFile = Application.ExecutablePath;//获取带全路径的本程序
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true).SetValue("MyApp", FullPathFile);//将本程序加入到注册表的RUN中
MessageBox.Show("已设定开机就要启动本程序。", "信息提示", MessageBoxButtons.OK);
} private void button2_Click(object sender, EventArgs e)
{
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true).DeleteValue("MyApp", false);//将本程序从注册表的RUN中删除
MessageBox.Show("已取消开机就启动本程序。", "信息提示", MessageBoxButtons.OK);
}
注册表 run 项 : 也可以写到 runonce 里 然后那个程序每次都写一次...
.. 放到 ~\「开始」菜单\程序\启动 里