Here, I am going to explain how to get your system configuration in an email. Using this article, you can get your machine configuration and send it via an email, so if you want to get any machine information, then just run this code on a particular machine and get all the information related to the configuration of the machine. Here, I am running command from the command prompt and an output of command prompt; write to the string. Using systeminfo command, you can get all the configuration related stuff of your machine.
Step to follow
- Add the necessary namespace in the file given below.
- using System.Collections.Generic;
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Net.Mail;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- Run the command to get the information.
- System.Diagnostics.Process process = new System.Diagnostics.Process();
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
- startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
- startInfo.FileName = "cmd.exe";
- startInfo.Arguments = "/c systeminfo";
- startInfo.RedirectStandardOutput = true;
- startInfo.UseShellExecute = false;
- process.StartInfo = startInfo;
- process.Start();
- Read the output generated by the command and write it to the string.
- string output = process.StandardOutput.ReadToEnd(); process.WaitForExit();
- Send out a command via an email.
- MailMessage mail = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
- mail.From = new MailAddress("[email protected]");
- mail.To.Add("[email protected]");
- mail.Subject = "System Configurations";
- mail.IsBodyHtml = true;
- mail.Body = output;
- SmtpServer.Port = 465;
- SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
- SmtpServer.EnableSsl = true;
- SmtpServer.Send(mail);
- Application.Exit();