zoukankan      html  css  js  c++  java
  • C# WinForm 开机自动运行

    第一种方法:

    using Microsoft.Win32;

    private void Form1_Load(object sender, EventArgs e)
    {
        //获取程序执行路径..
        string starupPath = Application.ExecutablePath;
        //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
        RegistryKey loca = Registry.LocalMachine;
        RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
      
        try
        {
           //SetValue:存储值的名称
     run.SetValue("WinForm",starupPath);
     MessageBox.Show(" 注册表添加成功!!",""提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            loca.Close();
        }
        catch(Exception ee)
        {
            MessageBox.Show(ee.Message.ToString(),"提 示",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }

    第二种方法:
    添加到注册表里直接用代码写到注册表里,也可以手动添加.
    E:D:\\tractor.exe//可以是你的程序名和 完整路径就OK了.
    也可以手动拖到启动里面....

     RegistryKey hklm = Application.LocalMachine;
     RegistryKey run = hklm.CreateSubKey(@"SOFTWARE\Microsoft\Windows\Current\Version\Run");
     try
     {
        run.SetValue("tractor.exe","D:\\tractor.exe");
        MessageBox.Show("注册表添加成功!!","提示",MessageBoxButton.OK, MessageBoxIcon.Information);
        hklm.Close();
     }

     catch(Exception ee)
     {
        MessageBox.Show(my.Message.ToString(),"提示",MessageBoxButton.OK, MessageBoxIcon.Error);
      }

  • 相关阅读:
    OFDM系统中频域同步技术及FPGA实现
    SystemVerilog的挑战和机遇
    基础知识要牢固..复习复习,再复习
    样式在.net下测试不成功.附解决办法
    学习.net2.0的网站
    08年又快结束了..抱怨下!~
    今天去面试.net开发,感想
    在b/s开发中经常用到的javaScript技术
    淘宝"新版"首页
    Ajax技术简单入门
  • 原文地址:https://www.cnblogs.com/top5/p/1669681.html
Copyright © 2011-2022 走看看