Last active
February 1, 2017 19:08
-
-
Save karoltheguy/fa8a0668864a44339cbb4c3041252769 to your computer and use it in GitHub Desktop.
Start Citrix Session with reference wfica.ocx(not embedded interop)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using WFICALib; | |
class Program | |
{ | |
public static AutoResetEvent onLogonResetEvent = null; | |
/// This program demo's the basic of launching and ICO session from within an application. | |
static void Main(string[] args) | |
{ | |
ICAClientClass ica = new ICAClientClass(); | |
onLogonResetEvent = new AutoResetEvent(false); | |
// Launch published Notepad if you comment this line, and uncommented | |
// the one above you will launch a desktop session | |
//ica.Application = ""; | |
ica.InitialProgram = "#appname"; | |
// Launch a new session | |
ica.Launch = true; | |
// Set Server address | |
ica.Address = "servername"; | |
// No Password property is exposed (for security) | |
// but can explicitly specify it by using the ICA File "password" property | |
ica.Username = "username"; | |
ica.Domain = "domain"; | |
ica.SetProp("Password", "password here"); | |
// Needed in some cases | |
ica.EncryptionLevelSession = "EncRC5-128"; | |
// Let's have a "pretty" session | |
ica.DesiredColor = ICAColorDepth.Color24Bit; | |
// Reseach the output mode you want, depending on what your trying | |
// to attempt to automate. The "Client Simulation APIs" are only available under certain modes | |
// (i.e. things like sending keys to the session, enumerating windows, etc.) | |
ica.OutputMode = OutputMode.OutputModeNormal; | |
// Height and Width | |
ica.DesiredHRes = 1024; | |
ica.DesiredVRes = 786; | |
// Register for the OnLogon event | |
ica.OnLogon += new _IICAClientEvents_OnLogonEventHandler(ica_OnLogon); | |
// Launch/Connect to the session | |
ica.Connect(); | |
Session test = ica.Session; | |
if (onLogonResetEvent.WaitOne(new TimeSpan(0, 2, 0))) | |
{ | |
Console.WriteLine("Session Logged on sucessfully! And OnLogon Event was Fired!"); | |
//Not Working for me | |
int AppCount = ica.EnumerateApplications(); | |
for (int i = 0; i < AppCount; i++) | |
{ | |
string appName = ica.GetEnumNameByIndex(AppCount, i); | |
Console.WriteLine("Application_" + i + " " + appName); | |
} | |
} | |
else | |
Console.WriteLine("OnLogon event was NOT Fired! Logging off ..."); | |
// Do we have access to the client simulation APIs? | |
if (ica.Session == null) | |
Console.WriteLine("ICA.Session object is NULL! :("); | |
Console.WriteLine("\nPress any key to log off"); | |
Console.Read(); | |
// Logoff our session | |
Console.WriteLine("Logging off Session"); | |
ica.Logoff(); | |
} | |
/// <summary> | |
/// OnLogon event handler | |
/// </summary> | |
static void ica_OnLogon() | |
{ | |
Console.WriteLine("OnLogon event was Handled!"); | |
onLogonResetEvent.Set(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to run the client application as a Windows service.If I do that connect call is returning error code 13.