تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] ممكن كود تشغيل ملف bat من resources
#1
ممكن كود تشغيل ملف bat من resources
الرد }}}
تم الشكر بواسطة:
#2
(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); 
الرد }}}
تم الشكر بواسطة:
#3
كود :
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();
       }
   }
}
الرد }}}
تم الشكر بواسطة:
#4
الاستدعاء من داخل 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 ب اسم برنامجك
الرد }}}
تم الشكر بواسطة:
#5
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
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم