C# Bilgisayarı Kapatma ( Zaman Ayarlı )

R

ravex

Ultra Member
Joined
Jul 30, 2019
Messages
661
Reaction score
356
Location
Turkey
Bu yazımızda C# Windows Form projesi kullanarak ayarlanan zamana göre (saat,dakika,saniye) bilgisayarın kapanmasını sağlayan bir örnek gerçekleştireceğiz.
Formumuz aşağıdaki gibi olacak ve ilave olarak Timer nesnesi ekleyeceğiz. “Şimdi Kapat” butonuna basıldığında bilgisayarın hemen kapatılmasını,”Zaman Ayarla ve Kapat” butonuna basıldığında ise ilgili textBox kontrollerinde belirtilen saat,dakika ve saniye bilgisine göre kapanmasını sağlayacağız.
1577567818472.png


Kodlarımızı yazmaya başlayalım. Öncelikle;

C#:
using System.Diagnostics;
ekliyoruz.
Şimdi Kapat butonu için kodlarımız;

C#:
private void button1_Click(object sender, EventArgs e)
        {
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "C:\\Windows\\system32\\shutdown.exe";
            psi.Arguments = "-f -s -t 0";
            Process.Start(psi);
        }
Zaman Ayarla ve Kapat butonu için ;
C#:
  textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            timer1.Start();
ve son olarak Timer_Tick için kodlarımız.
C#:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
private void timer1_Tick(object sender, EventArgs e)
        {
            string saat, dakika, saniye;
            saat = textBox1.Text;
            dakika = textBox2.Text;
            saniye = textBox3.Text;
 
 
            if ((Convert.ToString(DateTime.Now.Hour)) == saat && (Convert.ToString(DateTime.Now.Minute) == dakika) && (Convert.ToString(DateTime.Now.Second)) == saniye)
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = "C:\\Windows\\system32\\shutdown.exe";
                psi.Arguments = "-f -s -t 0";
                Process.Start(psi);
            }
        }










 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom