كيف اقدر انفذ اوامر الدوس من خلال برنامج بالسي شارب؟!
كيف انفذ اوامر الدوس من خلال برنامج بالسي شارب
System.Diagnostic.Process should get you in the right direction
For example if you want to excute a "dir" command then your code should be like this
System.Diagnostics.Process pro = new System.Diagnostics.Process(); pro.StartInfo.FileName = System.Environment.SystemDirectory + "cmd"; //this will start cmd.
to add the "dir" command then you should add it as an argument, i.e
pro.StartInfo.Arguments = " " + "dir" //this will complete the execution of your "dir" command
If you do not want the cmd window appear to users
pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Then finally start your process
pro.Start();
that's it
p.s: the above code won't work except for Win2k and WinXP
تم تعديل هذه المشاركة بواسطة abdelaleem في 8 أغسطس 2004 في 19:29
رأس الحكمة الإيمان بالله
System.Diagnostics.Process pro = new System.Diagnostics.Process(); pro.StartInfo.FileName = System.Environment.SystemDirectory + "\\cmd"; pro.StartInfo.Arguments = " " + "dir" pro.Start();
لما انفذ الكود اللي فوق, فانه يفتح لي نافذه دوس لكنه مايطبق الامر dir فيها!!!
pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
اما بالنسبة لكود اخفاء نافذه الدوس فانه لايعمل....
Sorry it was an air coded
Try another command instead of "dir", I was just sampling it to you ..or: what exactly commands you want to run
Regarding ProcessWindowStyle.Hidden.. I believe you are putting this line after the
pro.Start(), and that will not work, put it before pro.Start to work as you want
تم تعديل هذه المشاركة بواسطة abdelaleem في 11 أغسطس 2004 في 01:06
رأس الحكمة الإيمان بالله
اخوي جربت عدة اوامر اخرى مثل:
edit, copy, copydisk,..........
ولكنها لم تنفع!!!
اما بالنسبة لـ ProcessWindowStyle.Hidden فان المشكلة ليس في وضعها قبل Pro.Strart او بعدها....
لان الكمبايلر يظهر خطأ في الجملة نفسها اي انه لايوجد امر او تركيب اسمه ProcessWindowStyle.Hidden في السي شارب.
-------------------------------------------------------------------
وانا احتاج اني اعرف طريقة تنفيذ الاوامر من الدوس
لان عندي حوالي 5000 ملف صوتي من نسق VOX وابغى احولهم لنسق WAV. وحصلت على برنامج للتحويل اسمه towav.exe يعمل في بيئة الدوس.
ولكن صعبه اني اقعد امشي على 5000 ملف واقوم بتحويلهم واحد..واحد.
ومن الافضل والأسرع اني اسوي باتش بالسي شارب يقوم بتحويل الملفات مره واحده.
تم تعديل هذه المشاركة بواسطة AL-Baheth في 11 أغسطس 2004 في 17:17
السلام عليكم , اخي الباحث جرب هذا الكود لعله ينفعك
try
{
for(int i=0;i<3;i++)//طبعاً اللوب بعدد الملفات
{
System.IO.StreamWriter str=new System.IO.StreamWriter(@"c:\ta\run.bat");//ضع الملف في اي مكان يحلو لك
str.WriteLine("dir c"); // c:\conv file"+i+".vox اكتب هنا امر التحويل مع تغير اسم الف ليوافق الملف التالي , مثال
str.Close();
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName="c:\\ta\\run.bat";
proc.Start();
System.Threading.Thread.Sleep(250);//for some delay
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}هذا الموضوع مغلق.