Jump to content

martins_044

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. martins_044

    Any delphi components for VNC or RemoteDesktop?

    Can you help me? (Don't mind the writing and indentation of the code, it's really bad, this language is new to me) unit tbConnectRDP; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, MSTSCLib_TLB, ActiveX, ComObj, Vcl.OleServer, Vcl.OleCtrls, Generics.Collections; type TConnectRDP = class(TForm) treeListServer: TTreeView; listServerSplitter: TSplitter; pageControlViewServer: TPageControl; procedure ConectarRDP( const IP, Usuario, Senha: string ); procedure treeListServerDblClick(Sender: TObject); procedure addServersListTree; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private FRDPConnections: TObjectList<TMsRdpClient10>; procedure RDPDisconnected(Sender: TObject; discReason: Integer); procedure pageControlViewServerDrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); procedure pageControlViewServerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); public { Public declarations } end; var ConnectRDP: TConnectRDP; implementation {$R *.dfm} uses tbMenu; procedure TConnectRDP.FormCreate(Sender: TObject); begin CoInitialize(nil); FRDPConnections := TObjectList<TMsRdpClient10>.Create(True); // True para liberar objetos ao destruir addServersListTree; pageControlViewServer.OwnerDraw := True; pageControlViewServer.OnDrawTab := pageControlViewServerDrawTab; pageControlViewServer.OnMouseDown := pageControlViewServerMouseDown; end; procedure TConnectRDP.FormDestroy(Sender: TObject); begin FRDPConnections.Free; CoUninitialize; end; procedure TConnectRDP.addServersListTree; var Grupo: TTreeNode; begin // Limpa a TreeView antes de adicionar treeListServer.Items.Clear; // Adiciona um grupo chamado "Produção" Grupo := treeListServer.Items.Add(nil, 'Produção'); treeListServer.Items.AddChild(Grupo, '10.1.1.96'); treeListServer.Items.AddChild(Grupo, '10.1.1.200'); treeListServer.Items.AddChild(Grupo, '10.1.1.233'); // Adiciona outro grupo chamado "Testes" Grupo := treeListServer.Items.Add(nil, 'Testes'); treeListServer.Items.AddChild(Grupo, '192.168.100.10'); // Expande os grupos para facilitar visualização // treeListServer.FullExpand; end; procedure TConnectRDP.treeListServerDblClick(Sender: TObject); var ServerIP, Username, Password: string; begin if not Assigned(treeListServer.Selected) then Exit; if treeListServer.Selected.Parent = nil then Exit; // evita grupo ServerIP := treeListServer.Selected.Text; Username := 'Administrador'; Password := '!tsncs4606'; ConectarRDP(ServerIP, Username, Password); end; { procedure TConnectRDP.ConectarRDP(const IP, Usuario, Senha: string); var Node: TTreeNode; NovaAba: TTabSheet; RDPClientLocal: TMsRdpClient10; begin Node := treeListServer.Selected; if (Node = nil) or (Node.Parent = nil) then Exit; NovaAba := TTabSheet.Create(pageControlViewServer); NovaAba.PageControl := pageControlViewServer; NovaAba.Caption := Node.Text; RDPClientLocal := TMsRdpClient10.Create(NovaAba); RDPClientLocal.Parent := NovaAba; RDPClientLocal.Align := alClient; RDPClientLocal.Visible := True; RDPClientLocal.OnDisconnected := RDPDisconnected; RDPClientLocal.UserName := Usuario; RDPClientLocal.Domain := ''; RDPClientLocal.AdvancedSettings9.ClearTextPassword := Senha; RDPClientLocal.AdvancedSettings9.AuthenticationLevel := 0; RDPClientLocal.AdvancedSettings9.EnableCredSspSupport := True; RDPClientLocal.AdvancedSettings9.RedirectClipboard := False; RDPClientLocal.Server := IP; // FRDPConnections.Add(RDPClientLocal); try RDPClientLocal.Connect; except on E: Exception do ShowMessage('Erro ao conectar: ' + E.Message); end; end; } procedure TConnectRDP.RDPDisconnected(Sender: TObject; discReason: Integer); begin ShowMessage('Desconectado. Motivo: ' + IntToStr(discReason)); end; procedure TConnectRDP.ConectarRDP(const IP, Usuario, Senha: string); var Node: TTreeNode; NovaAba: TTabSheet; RDPClientLocal: TMsRdpClient10; NonScriptable: IMsRdpClientNonScriptable5; begin Node := treeListServer.Selected; if (Node = nil) or (Node.Parent = nil) then Exit; NovaAba := TTabSheet.Create(pageControlViewServer); NovaAba.PageControl := pageControlViewServer; NovaAba.Caption := Node.Text; RDPClientLocal := TMsRdpClient10.Create(NovaAba); RDPClientLocal.Parent := NovaAba; RDPClientLocal.Align := alClient; RDPClientLocal.Visible := True; RDPClientLocal.OnDisconnected := RDPDisconnected; // Configuração de automação total RDPClientLocal.UserName := Usuario; RDPClientLocal.Domain := ''; RDPClientLocal.AdvancedSettings9.ClearTextPassword := Senha; RDPClientLocal.AdvancedSettings9.AuthenticationLevel := 0; // Ignora certificado RDPClientLocal.AdvancedSettings9.EnableCredSspSupport := True; // Configurações avançadas de prompt e credenciais via NonScriptable if Supports( RDPClientLocal, IMsRdpClientNonScriptable5, NonScriptable) then begin NonScriptable.Set_AllowPromptingForCredentials(False); NonScriptable.Set_PromptForCredentials(False); NonScriptable.Set_PromptForCredsOnClient(False); NonScriptable.Set_AllowCredentialSaving(True); end; // Redirecionamento (opcional) RDPClientLocal.AdvancedSettings9.RedirectDrives := False; RDPClientLocal.AdvancedSettings9.RedirectPrinters := False; RDPClientLocal.AdvancedSettings9.RedirectClipboard := false; RDPClientLocal.Server := IP; try RDPClientLocal.Connect; except on E: Exception do ShowMessage('Erro ao conectar: ' + E.Message); end; end; procedure TConnectRDP.pageControlViewServerDrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); var TabCaption: string; CloseRect: TRect; begin TabCaption := pageControlViewServer.Pages[TabIndex].Caption; // Desenha o texto da aba Control.Canvas.TextRect( Rect, Rect.Left + 10, Rect.Top + 4, TabCaption ); // Desenha o "X" no canto direito da aba CloseRect := Rect; CloseRect.Left := CloseRect.Right - 25; CloseRect.Right := CloseRect.Right - 25; CloseRect.Top := CloseRect.Top + 4; CloseRect.Bottom := CloseRect.Bottom - 4; Control.Canvas.TextRect(CloseRect, CloseRect.Left, CloseRect.Top, 'X'); end; procedure TConnectRDP.pageControlViewServerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var i: Integer; TabRect: TRect; CloseRect: TRect; begin for i := 0 to pageControlViewServer.PageCount - 1 do begin TabRect := pageControlViewServer.TabRect(i); CloseRect := TabRect; CloseRect.Left := CloseRect.Right - 18; CloseRect.Right := CloseRect.Right - 4; if PtInRect(CloseRect, Point(X, Y)) then begin pageControlViewServer.Pages.Free; Break; end; end; end; end.
  2. martins_044

    Any delphi components for VNC or RemoteDesktop?

    I've been trying to implement this method for about two weeks, using MsTSCLib_TLB.pas. My problem may be my expectations of what could be done, as I would like an application like Remote Desktop Manager (RDM). I'm managing to make the connection and everything, but I'm stuck on these two validation tabs, maybe it's something in Windows, the big issue is that I've tried using several things and different ways, but I can't make something fluid and automatic, just by clicking and connecting.
×