Visual Studio C# ile yaptığınız programı bu kod sayesinde bilgisayar açıdlığında otomatik çalışacaktır.
Kullanacağımız Kütüphane:
using Microsoft.Win32;
Kullanacağımız Kod:
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue("ProgramAdı", "\"" + Application.ExecutablePath + "\"");
Metin…
Checkboxla Yaptırma:
private void otoçalş_CheckedChanged(object sender, EventArgs e)
{
if (otoçalş.Checked) // program oto başlatma işaretlenirse
{
//işaretlendi ise Regedit e açılışta çalıştır olarak ekle
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue("Kalan Zaman", "\"" + Application.ExecutablePath + "\"");
}
else //program oto çalıştırma iptal edilirse
{
//işaret kaldırıldı ise Regeditten açılışta çalıştırılacaklardan kaldır
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
key.DeleteValue("Kalan Zaman");
}
}
metin…
public Form1()
{
InitializeComponent();
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (key.GetValue("Kalan Zaman").ToString() == "\"" + Application.ExecutablePath + "\"")
{
// Eğer regeditte varsa, checkbox ı işaretle
otoçalş.Checked = true;
}
}
catch
{
}
}
Program Bittiğinde Bütün kodlar:
using Microsoft.Win32;
namespace Kalan_Zaman
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (key.GetValue("Kalan Zaman").ToString() == "\"" + Application.ExecutablePath + "\"")
{
// Eğer regeditte varsa, checkbox ı işaretle
otoçalş.Checked = true;
}
}
catch
{
}
}
private void otoçalş_CheckedChanged(object sender, EventArgs e)
{
if (otoçalş.Checked) // program oto başlatma işaretlenirse
{
//işaretlendi ise Regedit e açılışta çalıştır olarak ekle
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue("Kalan Zaman", "\"" + Application.ExecutablePath + "\"");
}
else //program oto çalıştırma iptal edilirse
{
//işaret kaldırıldı ise Regeditten açılışta çalıştırılacaklardan kaldır
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
key.DeleteValue("Kalan Zaman");
}
}