Force application launch on startup

前端 未结 4 556
萌比男神i
萌比男神i 2021-01-01 07:52

I am creating a kiosk like environment for my kids. My application scans and kills alot of game processes as they cannot play M or above rated games as they are quite young,

4条回答
  •  无人及你
    2021-01-01 08:16

    That's actually quite easy to do. Here are two code snippets you can use to do that. This copies your program into a folder that is rarely accessed then uses the computer's registry to open it on the computer's startup.

    Note: We use try and catch statements just in case, you should always use them.

    public static void AddToRegistry()
    {
           try
           {
               System.IO.File.Copy(Application.ExecutablePath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ATI\" + "msceInter.exe");
               RegistryKey RegStartUp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
               RegStartUp.SetValue("msceInter", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ATI\" + "msceInter.exe");
           }
           catch { }
    }
    

    Here is adding to start up (We copy our file into the startup folder, Start Button > All Programs > Start Up is where it will be found)

     public static void AddToStartup()
     {
           try
           {
               System.IO.File.Copy(Application.ExecutablePath, Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\" + "msceInter.exe");
           } 
           catch { }
     }
    

提交回复
热议问题