اقتباسأقدم لكم اليوم كود بسيط للغاية و هو حقيقة غير مكتمل 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
شرح الكود:
تنفيذ أوامر Dos في برنامجك و إظهار النتائج فيه
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
à 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 وبرامجي على موقعي الجديد :
هذا الموضوع مغلق.