Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Delphi - Richiamare le function da pc remoto delphi XE
Forum - Delphi - Richiamare le function da pc remoto delphi XE

Avatar
MrCamarium (Member)
Newbie


Messaggi: 6
Iscritto: 28/05/2013

Segnala al moderatore
Postato alle 7:42
Domenica, 13/02/2022
Ho comincaito a fare un po di ordine nel file server per intenderci il file installato sul PC remoto ho inserito le function:

Codice sorgente - presumibilmente Delphi

  1. [CODE]function Tipo_cpu: string;
  2.  
  3.     var
  4.  
  5.       aVendor: array[0..2] of DWord;
  6.  
  7.       iI, iJ : Integer;
  8.  
  9.     begin
  10.  
  11.       asm
  12.  
  13.         push ebx
  14.  
  15.         xor   eax, eax
  16.  
  17.         dw    $A20F // CPUID instruction
  18.  
  19.         mov   DWord ptr aVendor, ebx
  20.  
  21.         mov   DWord ptr aVendor[+4], edx
  22.  
  23.         mov   DWord ptr aVendor[+8], ecx
  24.  
  25.         pop   ebx
  26.  
  27.       end;
  28.  
  29.       for iI := 0 to 2 do
  30.  
  31.         for iJ := 0 to 3 do
  32.  
  33.         Result := Result + Chr((aVendor[iI] and ($000000FF shl (iJ * 8))) shr (iJ * 8));
  34.  
  35.     end;
  36.  
  37.  
  38.  
  39. function GetCPUSpeed: Double;
  40.  
  41. const
  42.  
  43.   DelayTime = 500;
  44.  
  45. var
  46.  
  47.   TimerHi, TimerLo: DWORD;
  48.  
  49.   PriorityClass, Priority: Integer;
  50.  
  51. begin
  52.  
  53.   PriorityClass := GetPriorityClass(GetCurrentProcess);
  54.  
  55.   Priority      := GetThreadPriority(GetCurrentThread);
  56.  
  57.   SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  58.  
  59.   SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
  60.  
  61.   Sleep(10);
  62.  
  63.   asm
  64.  
  65.     dw 310Fh
  66.  
  67.     mov TimerLo, eax
  68.  
  69.     mov TimerHi, edx
  70.  
  71.   end;
  72.  
  73.   Sleep(DelayTime);
  74.  
  75.   asm
  76.  
  77.     dw 310Fh
  78.  
  79.     sub eax, TimerLo
  80.  
  81.     sbb edx, TimerHi
  82.  
  83.     mov TimerLo, eax
  84.  
  85.     mov TimerHi, edx
  86.  
  87.   end;
  88.  
  89.   SetThreadPriority(GetCurrentThread, Priority);
  90.  
  91.   SetPriorityClass(GetCurrentProcess, PriorityClass);
  92.  
  93.   Result := TimerLo / (1000 * DelayTime);
  94.  
  95. end;
  96.  
  97.  
  98.  
  99. function IsSoundCardInstalled: Boolean;
  100.  
  101. Begin
  102.  
  103.    Result := waveOutGetNumDevs > 0;
  104.  
  105. End;
  106.  
  107.  
  108.  
  109. function InfoSO: String;
  110.  
  111. Var piattaforma: string;
  112.  
  113.        win_ver: integer;
  114.  
  115. Begin
  116.  
  117.  Case (Win32Platform) of VER_PLATFORM_WIN32_WINDOWS:
  118.  
  119.   Begin
  120.  
  121.     piattaforma := 'Windows 9x/Me';
  122.  
  123.     win_ver := Win32BuildNumber AND $0000FFFF;
  124.  
  125.  End;
  126.  
  127.  VER_PLATFORM_WIN32_NT:
  128.  
  129.  
  130.  
  131.    Begin
  132.  
  133.     piattaforma := 'Windows NT';
  134.  
  135.     win_ver := Win32BuildNumber;
  136.  
  137.    End;
  138.  
  139.  Else
  140.  
  141.   Begin
  142.  
  143.    piattaforma := 'Windows';
  144.  
  145.    win_ver := 0;
  146.  
  147.   End;
  148.  
  149.  End; // case
  150.  
  151. If (Win32CSDVersion = '') Then
  152.  
  153.     InfoSO := Format('%s %d.%d (Build %d)', [piattaforma,Win32MajorVersion,
  154.  
  155.                                   Win32MinorVersion,win_ver])
  156.  
  157.  Else
  158.  
  159.     InfoSO := Format('%s %d.%d (Build %d: %s)', [piattaforma,Win32MajorVersion,
  160.  
  161.                                Win32MinorVersion,win_ver,WIN32CSDVersion]);
  162.  
  163. End;
  164.  
  165.  
  166.  
  167. function SysComputerName: string;
  168.  
  169. var
  170.  
  171.   I: DWord;
  172.  
  173. begin
  174.  
  175.   I := MAX_COMPUTERNAME_LENGTH + 1;
  176.  
  177.   SetLength(Result, I);
  178.  
  179.   Windows.GetComputerName(PChar(Result), I);
  180.  
  181.   Result := string(PChar(Result));
  182.  
  183. end;
  184.  
  185.  
  186.  
  187. function SysUserName: string;
  188.  
  189. var
  190.  
  191.   I: DWord;
  192.  
  193. begin
  194.  
  195.   I := 255;
  196.  
  197.   SetLength(Result, I);
  198.  
  199.   Windows.GetUserName(PChar(Result), I);
  200.  
  201.   Result := string(PChar(Result));
  202.  
  203. end;[/CODE]



Adesso come faccio dal mio programma cioè il file cliente installato sulla mia macchina a richiamare le function?

PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6404
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 8:37
Domenica, 13/02/2022
Non si capisce niente


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
MrCamarium (Member)
Newbie


Messaggi: 6
Iscritto: 28/05/2013

Segnala al moderatore
Postato alle 21:31
Mercoledì, 16/02/2022
Ho un problema su questo codice:
Codice sorgente - presumibilmente Delphi

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  8.   IdIOHandler, IdGlobal, StdCtrls, IdStack;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     Label1: TLabel;
  14.     Button2: TButton;
  15.     client: TIdTCPClient;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure Button2Click(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.   client: TIdTCPClient;
  27.  
  28. implementation
  29.  
  30. {$R *.dfm}
  31.  
  32. function Tipo_cpu: string;
  33.     var
  34.       aVendor: array[0..2] of DWord;
  35.       iI, iJ : Integer;
  36.     begin
  37.       asm
  38.         push ebx
  39.         xor   eax, eax
  40.         dw    $A20F // CPUID instruction
  41.         mov   DWord ptr aVendor, ebx
  42.         mov   DWord ptr aVendor[+4], edx
  43.         mov   DWord ptr aVendor[+8], ecx
  44.         pop   ebx
  45.       end;
  46.       for iI := 0 to 2 do
  47.         for iJ := 0 to 3 do
  48.         Result := Result + Chr((aVendor[iI] and ($000000FF shl (iJ * 8))) shr (iJ * 8));
  49.     end;
  50.  
  51. function GetCPUSpeed: Double;
  52. const
  53.   DelayTime = 500;
  54. var
  55.   TimerHi, TimerLo: DWORD;
  56.   PriorityClass, Priority: Integer;
  57. begin
  58.   PriorityClass := GetPriorityClass(GetCurrentProcess);
  59.   Priority      := GetThreadPriority(GetCurrentThread);
  60.   SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  61.   SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
  62.   Sleep(10);
  63.   asm
  64.     dw 310Fh
  65.     mov TimerLo, eax
  66.     mov TimerHi, edx
  67.   end;
  68.   Sleep(DelayTime);
  69.   asm
  70.     dw 310Fh
  71.     sub eax, TimerLo
  72.     sbb edx, TimerHi
  73.     mov TimerLo, eax
  74.     mov TimerHi, edx
  75.   end;
  76.   SetThreadPriority(GetCurrentThread, Priority);
  77.   SetPriorityClass(GetCurrentProcess, PriorityClass);
  78.   Result := TimerLo / (1000 * DelayTime);
  79. end;
  80.  
  81. function InfoSO: String;
  82. Var piattaforma: string;
  83.        win_ver: integer;
  84. Begin
  85.  Case (Win32Platform) of VER_PLATFORM_WIN32_WINDOWS:
  86.   Begin
  87.     piattaforma := 'Windows 9x/Me';
  88.     win_ver := Win32BuildNumber AND $0000FFFF;
  89.  End;
  90.  VER_PLATFORM_WIN32_NT:
  91.  
  92.    Begin
  93.     piattaforma := 'Windows NT';
  94.     win_ver := Win32BuildNumber;
  95.    End;
  96.  Else
  97.   Begin
  98.    piattaforma := 'Windows';
  99.    win_ver := 0;
  100.   End;
  101.  End; // case
  102. If (Win32CSDVersion = '') Then
  103.     InfoSO := Format('%s %d.%d (Build %d)', [piattaforma,Win32MajorVersion,
  104.                                   Win32MinorVersion,win_ver])
  105.  Else
  106.     InfoSO := Format('%s %d.%d (Build %d: %s)', [piattaforma,Win32MajorVersion,
  107.                                Win32MinorVersion,win_ver,WIN32CSDVersion]);
  108. End;
  109.  
  110. function SysComputerName: string;
  111. var
  112.   I: DWord;
  113. begin
  114.   I := MAX_COMPUTERNAME_LENGTH + 1;
  115.   SetLength(Result, I);
  116.   Windows.GetComputerName(PChar(Result), I);
  117.   Result := string(PChar(Result));
  118. end;
  119.  
  120. function SysUserName: string;
  121. var
  122.   I: DWord;
  123. begin
  124.   I := 255;
  125.   SetLength(Result, I);
  126.   Windows.GetUserName(PChar(Result), I);
  127.   Result := string(PChar(Result));
  128. end;
  129.  
  130. function ReadMessage(io: TIdIOHandler; var kind: Byte) : TIdBytes;
  131. var
  132.   len: UInt32;
  133. begin
  134.   len := io.ReadLongWord();
  135.   kind := io.ReadByte;
  136.   SetLength(Result, len);
  137.   io.ReadBytes(Result, len, False);
  138. end;
  139.  
  140. function BytesToStr(b: TIdBytes): string;
  141. begin
  142.   Result := TEncoding.UTF8.GetString(b);
  143. end;
  144.  
  145. function StrToBytes(s: string) : TIdBytes;
  146. var
  147.   b: TBytes;
  148.   len: Integer;
  149. begin
  150.   b := TEncoding.UTF8.GetBytes(s);
  151.   len := Length(b);
  152.   SetLength(Result, len);
  153.   CopyMemory(Result, b, len);
  154. end;
  155.  
  156. function HandleResponse(h: TIdIOHandler): Boolean;
  157. begin
  158.   result:= FALSE;
  159. end;
  160.  
  161. function WaitForCommand(args: Pointer): Cardinal; stdcall;
  162. begin
  163.     while client.Connected do
  164.         if not HandleResponse(client.IOHandler) then
  165.             break;
  166.     Result := 0;
  167. end;
  168.  
  169. procedure WriteMessage(io: TIdIOHandler; kind: Byte; msg: TIdBytes);
  170. var
  171.   len: UInt32;
  172. begin
  173.   len := Length(msg);
  174.   io.Write(len);
  175.   io.Write(kind);
  176.   io.Write(msg);
  177. end;
  178.  
  179. procedure SendHello(io: TIdIOHandler);
  180. var
  181.   cpu: string;
  182.   so: string;
  183.   username: string;
  184.   pcname: string;
  185.   hello: string;
  186. begin
  187.   cpu := Tipo_cpu;
  188.   so := InfoSO;
  189.   username := SysUserName;
  190.   pcname := SysComputerName;
  191.   hello := cpu + '|' + so + '|' + username + '|' + pcname;
  192.   WriteMessage(io, 1, StrToBytes(hello));
  193. end;
  194.  
  195. procedure TForm1.Button1Click(Sender: TObject);
  196. var
  197.   client: TIdTCPClient;
  198. begin
  199.   client := TIdTCPClient.Create;
  200.   client.Port := 2630;
  201.   client.Host := '127.0.0.1';
  202.   client.ReadTimeout := 10000;
  203.   client.Connect;
  204.   Label1.Caption := 'Connesso'
  205.   end;
  206.  
  207. procedure TForm1.Button2Click(Sender: TObject);
  208. var
  209.     dwThread: Cardinal;
  210. begin
  211.     SendHello(client.IOHandler);
  212.     CreateThread(nil, 0, @WaitForCommand, nil, 0, dwThread);
  213. end;
  214.  
  215. end.



Quando clicco sul bottone 2 mi restituisce una finestra con un errore di memoria.

Ultima modifica effettuata da MrCamarium il 24/02/2022 alle 11:37
PM Quote