الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تنفيذ أوامر Dos في برنامجك و إظهار النتائج فيه

مغلق
بدأه Ayoub JAMAL EL IDRISSI في 16 أكتوبر 2007 · 2 رد · 952 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
اقتباس
أقدم لكم اليوم كود بسيط للغاية و هو حقيقة غير مكتمل 100 بالمئة لكن على الأقل سيقدم فكرة عما اريد ان اوصل اليكم و الهدف منه انه يمكنكم من تنفيذ بعض (و ليس كل) الأوامر الخاصة بالدوس

واظهار النتائج في برنامجكم مباشرة دون الحاجة للمرور او رؤية الشاشة السوداء الكود الخاص بهذه العملية هو التالي :

في فورم ننشئ :

زر أمر

TextBox1

TextBox2

والكود هو :

Imports System.IO

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

1: If Dir("c:\Temp.dos") <> "" Then Kill("c:\Temp.dos")

2: If TextBox1.Text = "clr" Then

3: TextBox2.Text = ""

4: Exit Sub

5: End If

6: Shell("cmd.exe /c " & TextBox1.Text & "> c:\Temp.dos", 7:AppWinStyle.Hide)

8: Try

9:ReadData:

10: Dim OpenResult As New StreamReader("c:\Temp.dos")

11: TextBox2.Text = OpenResult.ReadToEnd

12: OpenResult.Close()

13: Catch ex As FileNotFoundException

14: GoTo ReadData

15: Catch ex2 As IOException

16: GoTo ReadData

17: End Try

18: Application.DoEvents()

19: End Sub

20:End Class

شرح الكود:

رابط الموضوع كاملا

#2

Another way to do this without FILES :

insert this code in a function it returns a String object containing the result of a request sent to a DOS program like "ipconfig" included in windows

------------------------------------------------

Dim info As ProcessStartInfo = New ProcessStartInfo() 'processinfo

info.FileName = filename 'nom du prog DOS "console" a executer .exe ou .com

info.Arguments = arguments 'liste des arguments necessaire a l'execution

info.UseShellExecute = False ' si le shell du système d'exploitation doit être utilisé pour démarrer le processus

info.RedirectStandardOutput = True 'valeur qui indique si la sortie d'une application est écrite dans le flux

info.CreateNoWindow = True 'sans fenetre visible

Dim output As String = String.Empty

Try

Dim p As Process = Process.Start(info) 'execution

p.Start()

output = p.StandardOutput.ReadToEnd() 'lecture du resultat complet

p.WaitForExit()

p.Close()

Catch ex As Exception

MessageBox.Show(ex.ToString())

End Try

Return output 'retour du text visible sur la console

-----------------------------------------------------------------

Youssef Maroc

#3

à cy60rg :

par koi je doi remplacer "Filename" et "argument" dans ces 2 lignes

اقتباس
 
info.FileName = filename 'nom du prog DOS "console" a executer .exe ou .com
info.Arguments = arguments 'liste des arguments necessaire a l'execution

parce que je les deja remplacé "Filename" par "command.exe" et "argument" par "ipconfig" mais ya rien comme resultats

مقالاتي في VB.NET وبرامجي على موقعي الجديد :

هذا الموضوع مغلق.

مواضيع مشابهة