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.Diagnostics;
- using System.Threading;
- using System.IO;
- using System.Runtime.InteropServices;
- namespace Game_Lister
- {
- public class Program
- {
- public static int running = 0;
- public static string proname = "lol";
- public static int liefzeit = 0;
- public static DateTime starttime = DateTime.Now;
- public static int send = 0;
- public static int nowindow = 1;
- public static string buffed = "fail";
- [DllImport("user32.dll")]
- private static extern IntPtr GetForegroundWindow();
- [DllImport("user32.dll")]
- private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
- static void Main(string[] args)
- {
- Thread[] ta = new Thread[1];
- for (int j = 0; j < 1; j++)
- {
- ta[j] = new Thread(new ThreadStart(process));
- ta[j].Start();
- ta[j] = new Thread(new ThreadStart(console));
- ta[j].Start();
- }
- while (true)
- { }
- }
- public static void process()
- {
- while (true)
- {
- Thread.Sleep(1000);
- try
- {
- using (StreamReader sr = new StreamReader("Process.txt"))
- {
- string line;
- while ((line = sr.ReadLine()) != null)
- {
- string[] teile = line.Split(',');
- string process = teile[0];
- string name = teile[1];
- Process[] processlist = Process.GetProcesses();
- foreach (Process theprocess in processlist)
- {
- int chars = 256;
- StringBuilder buff = new StringBuilder(chars);
- IntPtr handle = GetForegroundWindow();
- if (GetWindowText(handle, buff, chars) > 0)
- {
- buffed = Convert.ToString(buff);
- }
- if (process == theprocess.ProcessName && buffed == name )
- {
- IntPtr window = theprocess.MainWindowHandle;
- running = 1;
- proname = name;
- starttime = theprocess.StartTime;
- Thread[] ta = new Thread[1];
- for (int j = 0; j < 1; j++)
- {
- ta[j] = new Thread(new ThreadStart(database));
- Console.WriteLine(window);
- theprocess.WaitForExit();
- running = 0;
- ta[j].Start();
- while (send != 1)
- {
- }
- ta[j].Abort();
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("The file could not be read:");
- Console.WriteLine(e.Message);
- }
- }
- }
- public static void console()
- {
- while (true)
- {
- if (proname != "lol")
- {
- if (running == 1)
- {
- var laufzeit = DateTime.Now - starttime;
- var runningsec = laufzeit.TotalSeconds;
- liefzeit = Convert.ToInt32(runningsec);
- Console.WriteLine(proname + " is running for " + liefzeit + " seconds");
- Thread.Sleep(100);
- Console.Clear();
- }
- if (running == 0)
- {
- Console.WriteLine(proname + " was running for " + liefzeit + " seconds");
- Thread.Sleep(1000);
- proname = "lol";
- Console.Clear();
- }
- }
- }
- }
- public static void database()
- {
- Console.WriteLine("SENDEN AN SERVER..."+ liefzeit);
- Console.ReadKey();
- send = 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment