Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Net.Mail;
- namespace Storage_Space_Checker
- {
- class Program
- {
- static void Main(string[] args)
- {
- string drive = @"C:\";
- float alertIfLower = 1.0f;
- bool hasAlerted = false;
- if (args.Length == 2)
- {
- drive = args[0];
- alertIfLower = float.Parse(args[1]);
- }
- while (true)
- {
- foreach (DriveInfo d in DriveInfo.GetDrives())
- {
- if (d.Name == drive)
- {
- float freeSpace = d.TotalFreeSpace / 1024f / 1024f / 1024f;
- Console.WriteLine(freeSpace.ToString("####.00"));
- if (freeSpace < alertIfLower)
- {
- if (!hasAlerted)
- {
- SmtpClient client = new SmtpClient();
- client.Port = 25;
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- client.UseDefaultCredentials = false;
- client.Host = "192.168.1.5";
- mail.Subject = "Disk Space Full!";
- mail.Body = "Disk space on drive " + drive + " in computer " + Environment.MachineName + " is full.";
- client.Send(mail);
- hasAlerted = true;
- }
- }
- else
- {
- hasAlerted = false;
- }
- }
- }
- Thread.Sleep(5000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement