منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : ممكن كود تشغيل ملف bat من resources
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
ممكن كود تشغيل ملف bat من resources
(06-01-23, 08:51 PM)jam3h كتب : [ -> ]ممكن كود تشغيل ملف bat من resources

PHP كود :
String bf = @"D:\batchfile.bat";
System.IO.File.WriteAllText(bfProperties.Resources.batchfile);
System.Diagnostics.Process.Start(bf); 
كود :
using System;
using System.IO;
using System.Reflection;

namespace YourNamespace
{
   class Program
   {
       static void Main(string[] args)
       {
           // اسم الملف الذي تم تضمينه في المصدر
           string resourceName = "YourNamespace.Resources.YourFile.bat";

           // استخراج الملف من المصدر
           Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);

           if (resourceStream != null)
           {
               // تحويل محتوى الملف إلى مصفوفة بايت
               byte[] fileBytes = new byte[resourceStream.Length];
               resourceStream.Read(fileBytes, 0, (int)resourceStream.Length);

               // تخزين الملف في مسار مؤقت
               string tempFilePath = Path.GetTempFileName();
               File.WriteAllBytes(tempFilePath, fileBytes);

               // تشغيل الملف BAT
               System.Diagnostics.Process.Start(tempFilePath);
           }
           else
           {
               Console.WriteLine("تعذر العثور على الملف في المصدر.");
           }

           Console.ReadLine();
       }
   }
}
الاستدعاء من داخل Resources
IO.File.WriteAllBytes(My.Computer.FileSystem.SpecialDirectories.Temp & "\file.bat", My.Resources.file)
Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "\file.bat")

استبدال file.bat ب اسم برنامجك
A batch file is a text file that contains a sequence of commands for a computer operating system. Batch files encapsulate multiple commands into a single file, and are created for command sequences that users employ repeatedly. 
Commonly used batch files are part of most operating systems. The sequence of commands in the batch file is initiated by entering the name of the batch file on the command line.

pikashow download