/// <summary> /// Stops the remote host from sending further updates and disconnects. /// </summary> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is not already in the Connected state. See <see cref="VncSharp.RemoteDesktop.IsConnected" />.</exception> public void Disconnect() { InsureConnection(true); vnc.ConnectionLost -= new EventHandler(VncClientConnectionLost); vnc.Disconnect(); SetState(RuntimeState.Disconnected); OnConnectionLost(); Invalidate(); }
/// <summary> /// Stops the remote host from sending further updates and disconnects. /// </summary> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is not already in the Connected state. See <see cref="VncSharp.RemoteDesktop.IsConnected" />.</exception> public void Disconnect() { InsureConnection(true); vnc.ConnectionLost -= VncClientConnectionLost; vnc.ServerCutText -= VncServerCutText; vnc.Disconnect(); SetState(RuntimeState.Disconnected); OnConnectionLost(); Invalidate(); }
static void GetFrame(string ip_address, string password, string output_dir) { GotFrame = false; try { VncClient vnc = new VncClient(); vnc.Connect(ip_address); vnc.Authenticate(password); vnc.Initialize(); vnc.StartUpdates(); Framebuffer = new Bitmap(vnc.Framebuffer.Width, vnc.Framebuffer.Height, PixelFormat.Format32bppPArgb); vnc.VncUpdate += new VncUpdateHandler(vnc_VncUpdate); DateTime FrameGrabTimeout = DateTime.Now.AddSeconds(30); while (!GotFrame) { if (DateTime.Now > FrameGrabTimeout) break; Thread.Sleep(500); } vnc.Disconnect(); if (output_dir.Length == 0) output_dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); DirectoryInfo dir = new DirectoryInfo(output_dir); dir.Create(); Framebuffer.Save(dir.FullName + "\\" + ip_address + ".png", ImageFormat.Png); } catch (ObjectDisposedException s) { Console.Write("ERROR authenticating to " + ip_address + ".\n\r"); return; } catch (Exception e) { Console.Write("ERROR contacting " + ip_address + ". " + e.Message + "\n\r"); return; } Console.Write("Captured " + ip_address + "\n\r"); }