-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (40 loc) · 1.49 KB
/
Program.cs
File metadata and controls
53 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace KeepRDPAlive
{
static class Program
{
private static bool RefreshRDPWindow(string remoteHost)
{
var window = WindowHelper.FindTerminalServicesWindowByHost(remoteHost);
if (window == IntPtr.Zero) return false;
bool isMinimized = WindowHelper.IsIconic(window);
var fwwindow = WindowHelper.GetForegroundWindow();
if (fwwindow != window) WindowHelper.SetForegroundWindow(window);
if (isMinimized) SendMessageHelper.RestoreWindow(window);
KeyboardHelper.SendNoise();
if (isMinimized) SendMessageHelper.MinimizeWindow(window);
if (fwwindow != window) WindowHelper.SetForegroundWindow(fwwindow);
return true;
}
static int Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: KeepRDPAlive <hostname> [<hostname> ...]");
return -1;
}
while (true)
{
foreach (var hostname in args)
{
Console.Write("{0}: Poking {1}...", DateTime.Now, hostname);
Console.WriteLine( RefreshRDPWindow(hostname) ? "Success." : "Window not found." );
Thread.Sleep(1000);
}
Thread.Sleep(5*60*1000);
}
}
}
}