Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Wednesday, June 18, 2014

SetForegroundWindow Win32 API not always works on Windows 7

SetForegroundWindows has some remarks usage, which could be found here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx

At least one of the following must be true:
  • The process is the foreground process.
  • The process was started by the foreground process.
  • The process received the last input event.
  • There is no foreground process.
  • The foreground process is being debugged.
  • The foreground is not locked.
  • The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
  • No menus are active.
Alternative solution is to use  AttachedThreadInputAction pattern:


Other "classic" approaches using Mutexes and EventWaitHandle:



VB style approach:

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;    // Add reference to Microsoft.VisualBasic

namespace WindowsFormsApplication1 {
    class Program : WindowsFormsApplicationBase {
        public Program() {
            this.EnableVisualStyles = true;
            this.IsSingleInstance = true;
            this.MainForm = new Form1();
        }
        protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e) {
            e.BringToForeground = true;
        }
        [STAThread]
        public static void Main(string[] args) {
            new Program().Run(args);
        }
    }
}

Wednesday, December 8, 2010

"Load needed DLLs for kernel": Windows recovery console example

Lately I read a lot of people are having this error which stops your system from booting.
This is a very awful error which is solved by Microsoft with the solution to do a in-place install from Windows XP. This is a lot of work and I have a much safer and fast solution.
Boot your system from the Windows XP Cdrom and choose to repair your system which will put you in the "Recovery Console" mode.

Now make the following steps:

CHKDSK (which will fix the error(s) on your disk)
BOOTCFG /rebuild (you will rebuild your boot configuration now, 
just give enters when it asked extra info).
FIXBOOT (to fix your current bootsector)
FIXMBR (to fix your current master boot record).
EXIT (leaves the recovery console and reboots your system).

All should be fine now, however sometimes it is possible that you have to choose which operating system needs to be booted every time you switch on your system.

This can be easily solved when you are in Windows XP:
Go to START > right mouse button on MY COMPUTER > click PROPERTIES > click ADVANCED tab > in startup recovery click SETTINGS > choose your default operating system which is Windows XP > uncheck TIME TO DISPLAY LIST OF OPERATING SYSTEMS > click OK > click OK again.
This is all, your system will boot normally again.


Features about some commands:


bootcfg /rebuild


This utility will scan all your hard drive for any windows xp installations
and then displays the result.


The first prompt asks Add installation to boot list (Yes/No/All)
This is the name of the operating system, for example, type Windows XP Home and press enter.


The final prompt will be Enter OS load options:
Type /Fastdetect and press enter.


Additional command could be helpful:


bootcfg /scan
bootcfg /add

Powered by Blogger.