forked from andyjmorgan/CaffeineForCitrixWorkspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmHidden.cs
More file actions
141 lines (120 loc) · 4.65 KB
/
frmHidden.cs
File metadata and controls
141 lines (120 loc) · 4.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Caffeine
{
public partial class frmHidden : Form
{
private const string CCMRegPath = @"SOFTWARE\WOW6432Node\Citrix\ICA Client\CCM";
public frmHidden()
{
InitializeComponent();
}
private bool CheckCCMRegistryKeys()
{
List<string> ccmValues = new List<string>();
ccmValues.Add("AllowSimulationAPI");
ccmValues.Add("AllowLiveMonitoring");
using (var baseKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32))
{
var ccmKey = baseKey.OpenSubKey(CCMRegPath);
if (ccmKey != null)
{
foreach (string Value in ccmValues)
{
if ((int)ccmKey.GetValue(Value, -1) != 1)
{
return false;
}
}
return true;
}
}
return false;
}
private void Form1_Load(object sender, EventArgs e)
{
tmrTick.Interval = Properties.Settings.Default.TimerIntervalSeconds * 1000;
try
{
Debug.WriteLine("Testing ICA client object");
var icaClient = new WFICALib.ICAClient();
var version = icaClient.Version;
var enumHandle = icaClient.EnumerateCCMSessions();
var sessionCount = icaClient.GetEnumNameCount(enumHandle);
icaClient.CloseEnumHandle(enumHandle);
}
catch (Exception ex)
{
MessageBox.Show("An error occured while registering the ICA CCM Object", "Error on Startup", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
if (!CheckCCMRegistryKeys())
{
MessageBox.Show(@"The CCM registry DWORDS (AllowSimulationAPI & AllowLiveMonitoring) are missing from HKLM:\" + CCMRegPath, "Missing CCM values detected on Startup", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
Debug.WriteLine("Starting Timer");
tmrTick.Start();
this.Visible = false;
}
private void tmrTick_Tick(object sender, EventArgs e)
{
try
{
Debug.WriteLine("Timer Ticking");
var icaClient = new WFICALib.ICAClient();
var enumHandle = icaClient.EnumerateCCMSessions();
var sessionCount = icaClient.GetEnumNameCount(enumHandle);
Debug.WriteLine("Found {0} sessions", sessionCount);
int itemCount = 0;
while (itemCount < sessionCount)
{
try
{
Debug.WriteLine("Sending keepalive to session: {0}", itemCount);
string session = icaClient.GetEnumNameByIndex(enumHandle, itemCount);
WFICALib.ICAClient icaSession = new WFICALib.ICAClient();
icaSession.SetProp("OutputMode", "1");
icaSession.StartMonitoringCCMSession(session, true);
icaSession.Session.Keyboard.SendKeyDown(Properties.Settings.Default.KeyValue);//(int)Keys.B);
icaSession.StopMonitoringCCMSession(session);
}
catch (Exception ex)
{
Debug.WriteLine("Keepalive to session: {0} failed: {1}", itemCount, ex.ToString());
}
itemCount += 1;
}
icaClient.CloseEnumHandle(enumHandle);
}
catch(Exception ex)
{
Debug.WriteLine("Timer tick exception: {0}", ex.ToString());
}
}
private void frmHidden_Shown(object sender, EventArgs e)
{
this.Hide();
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
private void tsmiAbout_Click(object sender, EventArgs e)
{
frmAbout fa = new frmAbout();
fa.Show();
}
private void tsmiExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}