public static void connectWithManager() { try { client = new WebSocket(host); client.OnOpen += (ss, ee) => openUI(string.Format("Connected to {0} successfully", host)); client.OnError += (ss, ee) => displayError("Error: " + ee.Message); client.OnMessage += (ss, ee) => wrapperUpdateUI(ee.Data); client.OnClose += (ss, ee) => closeConnection(); client.Connect(); // build the connection request packet Process currentProcess = Process.GetCurrentProcess(); CrownRegisterRootObject registerRootObject = new CrownRegisterRootObject(); registerRootObject.message_type = "register"; registerRootObject.plugin_guid = "aa7c0911-fbf7-4e87-9c23-25987358303b"; registerRootObject.execName = "Unity.exe"; registerRootObject.PID = Convert.ToInt32(currentProcess.Id); string s = JsonConvert.SerializeObject(registerRootObject); // only connect to active session process registerRootObject.PID = Convert.ToInt32(currentProcess.Id); int activeConsoleSessionId = WTSGetActiveConsoleSessionId(); // This line throws errors on unity, replaced by something I believe does the same thing. //int currentProcessSessionId = Process.GetCurrentProcess().SessionId; client.Send(s); // if we are running in active session? /*if (currentProcessSessionId == activeConsoleSessionId) * { * client.Send(s); * } * else * { * UnityEngine.Debug.Log("Inactive user session. Skipping connect"); * }*/ } catch (Exception ex) { string str = ex.Message; } }
public static void connectWithManager() { try { client = new WebSocket(host); client.OnOpen += (ss, ee) => openUI(string.Format("Connected to {0} successfully", host)); client.OnError += (ss, ee) => displayError("Error: " + ee.Message); client.OnMessage += (ss, ee) => wrapperUpdateUI(ee.Data); client.OnClose += (ss, ee) => closeConnection(); client.Connect(); // build the connection request packet Process currentProcess = Process.GetCurrentProcess(); CrownRegisterRootObject registerRootObject = new CrownRegisterRootObject(); registerRootObject.message_type = "register"; registerRootObject.plugin_guid = "d510af8d-360f-4f3d-9216-20cd4f20f664"; registerRootObject.execName = "WinFormsCrownSample.exe"; registerRootObject.PID = Convert.ToInt32(currentProcess.Id); string s = JsonConvert.SerializeObject(registerRootObject); // only connect to active session process registerRootObject.PID = Convert.ToInt32(currentProcess.Id); int activeConsoleSessionId = WTSGetActiveConsoleSessionId(); int currentProcessSessionId = Process.GetCurrentProcess().SessionId; // if we are running in active session? if (currentProcessSessionId == activeConsoleSessionId) { client.Send(s); } else { Trace.TraceInformation("Inactive user session. Skipping connect"); } } catch (Exception ex) { string str = ex.Message; } }
private async Task Register(Process process, Guid guid) { CrownRegisterRootObject registerRootObject = new CrownRegisterRootObject(); registerRootObject.message_type = "register"; registerRootObject.plugin_guid = guid.ToString(); registerRootObject.execName = process.MainModule.ModuleName; registerRootObject.PID = Convert.ToInt32(process.Id); // only connect to active session process registerRootObject.PID = Convert.ToInt32(process.Id); int activeConsoleSessionId = Win32.WTSGetActiveConsoleSessionId(); // if we are running in active session? if (process.SessionId == activeConsoleSessionId) { await this.Send(registerRootObject); } }