开机自从运行写的C#程序
我查到一个方法是这样写的,有些地方不太明白,希望有经验的给讲解一下
我的应用程序包的名称为:数据转送,程序的名字为:frmStockCheck
第一个问题:RegistryKey用什么样的命名空间,使用什么样的参照。我运行时,出错
第二个问题 :倒数第二句话,key6.SetValue("frmStockCheck",exeDir);  里面用frmStockCheck这个名字对不?
顺便看看代码里面有没有写错的地方。在这里先谢谢大家
[align=left]
string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory,StartupPath+"frmStockCheck.cs",true);
                string dir = Directory.GetCurrentDirectory();
                string exeDir = dir+"frmStockCheck.exe";
RegistryKey   key1=Registry.LocalMachine;         
RegistryKey   key2=key1.CreateSubKey("SOFTWARE");         
RegistryKey   key3=key2.CreateSubKey("Microsoft");         
RegistryKey   key4=key3.CreateSubKey("Windows");         
RegistryKey   key5=key4.CreateSubKey("CurrentVersion");         
RegistryKey   key6=key5.CreateSubKey("Run");  
                  key6.SetValue("frmStockCheck",exeDir);         
              key6.Close();[/align]

解决方案 »

  1.   

    还有这句话System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory,StartupPath+"frmStockCheck.cs",true); 对不?
    帖子上是这样说的System.IO.File.Copy("应用程序路径(包括程序名)", StartupPath + "执行程序文件名称", true);        
      

  2.   

    我的方式                string strPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
                    RegistryKey ms_run = Registry.LocalMachine.OpenSubKey(strPath, true);
                    ms_run.SetValue("runApp", Application.ExecutablePath.ToString());
      

  3.   

    using Microsoft.Win32;就是通过向注册表中新加项来实现.
    你可以打开注册表中这个位置
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    里面每一项都是自动运行的.RegistryKey   key1=Registry.LocalMachine;          
    RegistryKey   key2=key1.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); 
    key2.SetValue(名字,路径);
      

  4.   

    要不就写WINDOWS服务
      

  5.   

    同意写成Windows服务,如果服务器在无人知晓的情况下断电重启后,如果不登录,Windows应用程序是无法运行的,此时会造成服务中断。
      

  6.   

    有没有比较好的资料介绍Windows服务的,.
    麻烦大家了。
      

  7.   

    ^ō^ 打包部署时将主程序的快捷方式放到(开始->所有程序->启动)目录下...
      

  8.   

    最简单的服务是在主类里面添加一个System.Timers.Timer类,定时执行任务。
    这里有一个例子,
    http://laiwen.cnblogs.com/archive/2005/09/29/246528.html
      

  9.   

    其实Windows服务从System.ServiceProcess.ServiceBase继承,楼主参考一下MSDN文档就可以写简单的服务。