Guest User

Untitled

a guest
Jul 9th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using System.Threading;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace Game_Lister
  11. {
  12. public class Program
  13. {
  14. public static int running = 0;
  15. public static string proname = "lol";
  16. public static int liefzeit = 0;
  17. public static DateTime starttime = DateTime.Now;
  18. public static int send = 0;
  19. public static int nowindow = 1;
  20. public static string buffed = "fail";
  21. [DllImport("user32.dll")]
  22. private static extern IntPtr GetForegroundWindow();
  23. [DllImport("user32.dll")]
  24. private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
  25.  
  26. static void Main(string[] args)
  27. {
  28. Thread[] ta = new Thread[1];
  29. for (int j = 0; j < 1; j++)
  30. {
  31. ta[j] = new Thread(new ThreadStart(process));
  32. ta[j].Start();
  33. ta[j] = new Thread(new ThreadStart(console));
  34. ta[j].Start();
  35. }
  36. while (true)
  37. { }
  38. }
  39. public static void process()
  40. {
  41. while (true)
  42. {
  43. Thread.Sleep(1000);
  44. try
  45. {
  46. using (StreamReader sr = new StreamReader("Process.txt"))
  47. {
  48. string line;
  49.  
  50. while ((line = sr.ReadLine()) != null)
  51. {
  52. string[] teile = line.Split(',');
  53. string process = teile[0];
  54. string name = teile[1];
  55.  
  56. Process[] processlist = Process.GetProcesses();
  57.  
  58. foreach (Process theprocess in processlist)
  59. {
  60. int chars = 256;
  61. StringBuilder buff = new StringBuilder(chars);
  62. IntPtr handle = GetForegroundWindow();
  63.  
  64. if (GetWindowText(handle, buff, chars) > 0)
  65. {
  66. buffed = Convert.ToString(buff);
  67. }
  68. if (process == theprocess.ProcessName && buffed == name )
  69. {
  70. IntPtr window = theprocess.MainWindowHandle;
  71. running = 1;
  72. proname = name;
  73. starttime = theprocess.StartTime;
  74. Thread[] ta = new Thread[1];
  75. for (int j = 0; j < 1; j++)
  76. {
  77. ta[j] = new Thread(new ThreadStart(database));
  78. Console.WriteLine(window);
  79. theprocess.WaitForExit();
  80. running = 0;
  81. ta[j].Start();
  82. while (send != 1)
  83. {
  84. }
  85. ta[j].Abort();
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. catch (Exception e)
  93. {
  94. Console.WriteLine("The file could not be read:");
  95. Console.WriteLine(e.Message);
  96. }
  97. }
  98. }
  99. public static void console()
  100. {
  101. while (true)
  102. {
  103. if (proname != "lol")
  104. {
  105. if (running == 1)
  106. {
  107. var laufzeit = DateTime.Now - starttime;
  108. var runningsec = laufzeit.TotalSeconds;
  109. liefzeit = Convert.ToInt32(runningsec);
  110. Console.WriteLine(proname + " is running for " + liefzeit + " seconds");
  111. Thread.Sleep(100);
  112. Console.Clear();
  113. }
  114. if (running == 0)
  115. {
  116. Console.WriteLine(proname + " was running for " + liefzeit + " seconds");
  117. Thread.Sleep(1000);
  118. proname = "lol";
  119. Console.Clear();
  120. }
  121. }
  122. }
  123. }
  124. public static void database()
  125. {
  126. Console.WriteLine("SENDEN AN SERVER..."+ liefzeit);
  127. Console.ReadKey();
  128. send = 1;
  129. }
  130. }
  131. }
Add Comment
Please, Sign In to add comment