Posts

Windows process managment through C#

#region Process Manipulation [ Flags ] public enum ThreadAccess : int { TERMINATE = ( 0x0001 ) , SUSPEND_RESUME = ( 0x0002 ) , GET_CONTEXT = ( 0x0008 ) , SET_CONTEXT = ( 0x0010 ) , SET_INFORMATION = ( 0x0020 ) , QUERY_INFORMATION = ( 0x0040 ) , SET_THREAD_TOKEN = ( 0x0080 ) , IMPERSONATE = ( 0x0100 ) , DIRECT_IMPERSONATION = ( 0x0200 ) } [ DllImport ( " kernel32.dll " ) ] static extern IntPtr OpenThread ( ThreadAccess dwDesiredAccess , bool bInheritHandle , uint dwThreadId ) ; [ DllImport ( " kernel32.dll " ) ] static extern uint SuspendThread ( IntPtr hThread ) ; [ DllImport ( " kernel32.dll " ) ] static extern int ResumeThread ( IntPtr hThread ) ; [ DllImport ( " kernel32 " , CharSet = CharSet . Auto , SetLastError = true ) ] static extern bool CloseHandle ( IntPtr handle ...

c# console applicaton progress bar with spinner

Image
Name spaces to include: using System; using System.Text; using System.Threading; ---------------------------------------------- Progress bar class:     class progressBar     {         /// <summary>         /// An ASCII progress bar         /// </summary>         public class ProgressBar : IDisposable, IProgress<double>         {             private const int blockCount = 40;             private readonly TimeSpan animationInterval = TimeSpan.FromSeconds(1.0 / 8);            private const string animation = @"▀▀▀▀▄▄▄▄";//@"▀▀▀▀▄▄▄▄"  @"|/-\";        ...

C# SELF DESTRUCT CONSOLE APP

Just call this method at the very end of your C# application to delete application’s executable file. /// <summary> /// This method deletes the exe that calls it. /// /// This method must be called right at the end of the application. /// </summary> private static void SelfDestroy() {      var startInfo = new ProcessStartInfo();      startInfo.FileName = "cmd.exe" ;      startInfo.RedirectStandardInput = true ;      startInfo.UseShellExecute = false ;        var process = new Process();      process.StartInfo = startInfo;      process.Start();        // The delay is just making sure the exe to delete is done      // running.      var delayPings = 2;      var exeName = AppDomain.CurrentDomain.Friend...