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);
      }
  • 相关阅读:
    魔法变量*args 和 **kwargs
    windows下怎么安装protobuf for python
    正向代理与反向代理
    Python 中 "is" 与 "==" 操作有什么区别?
    用 Anaconda 完美解决 Python2 和 python3 共存问题
    Python爬虫实例
    安装包制作工具 SetupFactory使用2 API清单
    软件测试流程(Test Flow)
    从一个实例详解敏捷测试的最佳实践
    网络常用基础知识大全
  • 原文地址:https://www.cnblogs.com/hantianwei/p/1674435.html
Copyright © 2011-2022 走看看