Šis straipsnis yra veidrodinis mašininio vertimo straipsnis, spauskite čia norėdami pereiti prie originalaus straipsnio.

Rodinys: 21067|Atsakyti: 0

[Šaltinis] Automatinio paleidimo exe paleidimo kodas .net?

[Kopijuoti nuorodą]
Paskelbta 2015-08-14 21:57:20 | | |
  1. public void SetAutoRun(string fileName, bool isAutoRun)   
  2. {   
  3.     RegistryKey reg = null;   
  4.     try
  5.     {   
  6.         if (!System.IO.File.Exists(fileName))   
  7.             throw new Exception("该文件不存在!");   
  8.         String name = fileName.Substring(fileName.LastIndexOf(@"") + 1);   
  9.         reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);   
  10.         if (reg == null)   
  11.             reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");   
  12.         if (isAutoRun)   
  13.             reg.SetValue(name, fileName);   
  14.         else
  15.             reg.SetValue(name, false);   
  16.         lbl_autorunerr.Visible = false;   
  17.     }   
  18.     catch
  19.     {   
  20.         lbl_autorunerr.Visible = true;   
  21.         //throw new Exception(ex.ToString());   
  22.     }   
  23.     finally
  24.     {   
  25.         if (reg != null)   
  26.             reg.Close();   
  27.     }   
  28. }
  29.         public void SetAutoRun(string fileName, bool isAutoRun)
  30.         {
  31.             RegistryKey reg = null;
  32.             try
  33.             {
  34.                 if (!System.IO.File.Exists(fileName))
  35.                     throw new Exception("该文件不存在!");
  36.                 String name = fileName.Substring(fileName.LastIndexOf(@"") + 1);
  37.                 reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
  38.                 if (reg == null)
  39.                     reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
  40.                 if (isAutoRun)
  41.                     reg.SetValue(name, fileName);
  42.                 else
  43.                     reg.SetValue(name, false);
  44.                 lbl_autorunerr.Visible = false;
  45.             }
  46.             catch
  47.             {
  48.                 lbl_autorunerr.Visible = true;
  49.                 //throw new Exception(ex.ToString());
  50.             }
  51.             finally
  52.             {
  53.                 if (reg != null)
  54.                     reg.Close();
  55.             }
  56.         }

  57. 使用的时候,直接调用SetAutoRun函数即可,这里解释一下两个参数的含义:

  58. fileName:需要设置自动启动程序的路径,若为当前程序可直接传递Application.ExecutablePath。

  59. isAutoRun:是否自动运行,为false时,取消自动运行。

  60. 例: SetAutoRun(Application.ExecutablePath, true); //设置自动启动当前程序

  61. SetAutoRun(Application.ExecutablePath, false); //取消自动启动
Kopijuoti kodą






Ankstesnis:Kaip nustatyti "Lenovo" nešiojamąjį kompiuterį, kad įkištumėte pelę ir uždarytumėte valdymo pultą
Kitą:Keli paprasti jquery praktikos klausimai su papildomais atsakymais
Atsakomybės apribojimas:
Visa programinė įranga, programavimo medžiaga ar straipsniai, kuriuos skelbia Code Farmer Network, yra skirti tik mokymosi ir mokslinių tyrimų tikslams; Aukščiau nurodytas turinys negali būti naudojamas komerciniais ar neteisėtais tikslais, priešingu atveju vartotojai prisiima visas pasekmes. Šioje svetainėje pateikiama informacija gaunama iš interneto, o ginčai dėl autorių teisių neturi nieko bendra su šia svetaine. Turite visiškai ištrinti aukščiau pateiktą turinį iš savo kompiuterio per 24 valandas nuo atsisiuntimo. Jei jums patinka programa, palaikykite autentišką programinę įrangą, įsigykite registraciją ir gaukite geresnes autentiškas paslaugas. Jei yra kokių nors pažeidimų, susisiekite su mumis el. paštu.

Mail To:help@itsvse.com