(25-11-2023, 08:42 AM)محمد الدرة كتب : الموضوع بسيط جدا كل ماتحتاجه الوصول الى اوامر cmd عندها يمكن كتابة الامر التالي
adb kill-server
adb start-server
الفكرة كلها تمحور حول استخدام CMD command الخاص بالويندوز
جرب البجث عليها هناك عدة امثلة
الموضوع ليس بسيط بالنسبة لي لانني مبتدئ في الدلفي
بحثت كثيرا ولم اجد اي مثال في الانترنت الا اني وجدت كود
لتشغيل cmd بالامر ShellExecute ومن ثم تشغيل adb.exe
وتمرير الاوامر ب CMD command
مثال هذا الكود لاعادة تشغيل الهاتف
shellexecute(0, 'open', 'cmd.exe ','/c adb.exe reboot', nil, SW_HIDE);
(25-11-2023, 06:51 PM)Delphi4Us كتب : وعليكم السلام ورحمة الله
فيما يلي مثال على كيفية استخدام أوامر ADB للتحكم في الهاتف في دلفي:
كود :unit ADB; interface uses SysUtils, System.IOUtils, System.Process, System.Diagnostics.ProcessUtils; type TADB = class private fADBPath: string; fDevice: string; public constructor Create(adbPath: string; device: string); procedure ExecuteCommand(command: string); end; implementation constructor TADB.Create(adbPath: string; device: string); begin fADBPath := adbPath; fDevice := device; end; procedure TADB.ExecuteCommand(command: string); var process: TProcess; output: string; begin process := TProcess.Create(fADBPath + ' ' + fDevice + ' ' + command); process.Start(); process.WaitFor(); output := process.Output; Debug.Print(output); end; end.
[size=1]هذا المث[/size]ال ينشئ كائنًا من فئة TADB. يأخذ هذا الكائن كوسيطين: مسار أداة ADB واسم الجهاز المراد التحكم فيه.
تستخدم الطريقة ExecuteCommand() لإرسال أمر ADB إلى الجهاز. يأخذ هذه الطريقة كوسيط واحد: الأمر الذي تريد إرساله.
فيما يلي مثال على كيفية استخدام هذا الكود:
كود :uses ADB; var adb: TADB; begin adb := TADB.Create('adb', 'localhost:5555'); adb.ExecuteCommand('shell ls'); end.
سيؤدي هذا الكود إلى طباعة قائمة بالملفات الموجودة في دليل الجذر للجهاز.
يمكنك استخدام هذا المثال كأساس لإنشاء تطبيقات مخصصة للتحكم في الهاتف باستخدام أوامر ADB. على سبيل المثال، يمكنك إنشاء تطبيق لفتح التطبيقات أو إيقاف تشغيلها أو تغيير إعدادات الجهاز.
كود :uses ..., Process; procedure ExecuteAdbCommand(const ACommand: string); var AProcess: TProcess; begin AProcess := TProcess.Create(nil); try // Set the Adb executable and arguments AProcess.Executable := 'adb'; AProcess.Parameters.Add(ACommand); // Redirect the output to a stream AProcess.Options := AProcess.Options + [poUsePipes]; AProcess.ShowWindow := swoHIDE; // Start the process AProcess.Execute; // Read the output from the stream while AProcess.Running do begin DoSomethingWithOutput(AProcess.Output); end; finally AProcess.Free; end; end; // Example usage: Restart the device procedure TForm1.RestartDevice; begin ExecuteAdbCommand('shell reboot'); end;
شكرا لك اخي سوف اجرب الاكواد ان شاء الله بارك الله فيك

