/// <summary> /// After protocol-level initialization and connecting is complete, the local GUI objects have to be set-up, and requests for updates to the remote host begun. /// </summary> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already in the Connected state. See <see cref="VncSharp.RemoteDesktop.IsConnected" />.</exception> protected void Initialize() { // Finish protocol handshake with host now that authentication is done. InsureConnection(false); vnc.Initialize(); SetState(RuntimeState.Connected); // Create a buffer on which updated rectangles will be drawn and draw a "please wait..." // message on the buffer for initial display until we start getting rectangles SetupDesktop(); // Tell the user of this control the necessary info about the desktop in order to setup the display OnConnectComplete(new ConnectEventArgs(vnc.Framebuffer.Width, vnc.Framebuffer.Height, vnc.Framebuffer.DesktopName)); // Refresh scroll properties AutoScrollMinSize = desktopPolicy.AutoScrollMinSize; // Start getting updates from the remote host (vnc.StartUpdates will begin a worker thread). vnc.VncUpdate += new VncUpdateHandler(VncUpdate); vnc.StartUpdates(); KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_LWIN, true); KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_RWIN, true); KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_ESCAPE, KeyboardHook.ModifierKeys.Control, true); KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_TAB, KeyboardHook.ModifierKeys.Alt, true); // TODO: figure out why Alt-Shift isn't blocked //KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_SHIFT, KeyboardHook.ModifierKeys.Alt, true); //KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_MENU, KeyboardHook.ModifierKeys.Shift, true); // TODO: figure out why PrtScn doesn't work //KeyboardHook.RequestKeyNotification(this.Handle, Win32.VK_SNAPSHOT, true); }
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"); }
/// <summary> /// After protocol-level initialization and connecting is complete, the local GUI objects have to be set-up, and requests for updates to the remote host begun. /// </summary> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already in the Connected state. See <see cref="VncSharp.RemoteDesktop.IsConnected" />.</exception> protected void Initialize() { // Finish protocol handshake with host now that authentication is done. InsureConnection(false); vnc.Initialize(); SetState(RuntimeState.Connected); // Create a buffer on which updated rectangles will be drawn and draw a "please wait..." // message on the buffer for initial display until we start getting rectangles SetupDesktop(); // Tell the user of this control the necessary info about the desktop in order to setup the display OnConnectComplete(new ConnectEventArgs(vnc.Framebuffer.Width, vnc.Framebuffer.Height, vnc.Framebuffer.DesktopName)); // Refresh scroll properties AutoScrollMinSize = desktopPolicy.AutoScrollMinSize; // Start getting updates from the remote host (vnc.StartUpdates will begin a worker thread). vnc.VncUpdate += new VncUpdateHandler(VncUpdate); vnc.StartUpdates(); }