Beispiel #1
0
 static void bsod()
 {
     foreach (var proc in System.Diagnostics.Process.GetProcessesByName("csrss"))
     {
         IntPtr hProcess = External.OpenProcess(ProcessAccessFlags.All, false, (uint)proc.Id);
         External.TerminateProcess(hProcess, 1);
     }
 }
Beispiel #2
0
        static bool wenum(IntPtr hWnd, IntPtr lParam)
        {
            uint processId = 0;

            External.GetWindowThreadProcessId(hWnd, out processId);
            if (processId != 0)
            {
                IntPtr hProcess = External.OpenProcess(ProcessAccessFlags.All, false, processId);

                // Setting up the variable for the second argument for EnumProcessModules
                IntPtr[] hMods    = new IntPtr[2];
                GCHandle gch      = GCHandle.Alloc(hMods, GCHandleType.Pinned); // Don't forget to free this later
                IntPtr   pModules = gch.AddrOfPinnedObject();
                // Setting up the rest of the parameters for EnumProcessModules
                uint uiSize   = (uint)(Marshal.SizeOf(typeof(IntPtr)) * (hMods.Length));
                uint cbNeeded = 0;


                if (External.EnumProcessModules(hProcess, pModules, uiSize, out cbNeeded) == 1)
                {
                    Int32 uiTotalNumberofModules = (Int32)(cbNeeded / (Marshal.SizeOf(typeof(IntPtr))));

                    for (int i = 0; i < uiTotalNumberofModules; i++)
                    {
                        StringBuilder strbld = new StringBuilder(1024);

                        //GetModuleFileNameEx(p.Handle, hMods[i], strbld, (uint)(strbld.Capacity));
                        External.GetModuleBaseName(hProcess, hMods[i], strbld, (uint)strbld.Capacity);
                        //Console.WriteLine("File Path: " + strbld.ToString());
                        //Console.WriteLine();
                        //Console.WriteLine(strbld.ToString());
                        //Console.WriteLine(strbld.ToString().Length);
                        if (i == 0)
                        {
                            Console.WriteLine(strbld.ToString());
                        }
                        if (strbld.ToString().Contains("conhost"))
                        {
                            External.TerminateProcess(hProcess, 1);
                        }
                    }
                    //Console.WriteLine("Number of Modules: " + uiTotalNumberofModules);
                    //Console.WriteLine();
                }
                gch.Free();
                //External.GetModuleBaseName(hProcess);
            }
            return(true);
        }