How can I open an aplication from registry to the foreground?

0

I have a Thinkpad T430 laptop, and this model in particular has a button on top of the keyboard that's literally called "Black Button". The button itself had no effect when I pressed it so I looked for what it should do. A lenovo utility program should pop up but it dindn't and I frankly didn't care. So I thought about remapping it to something more useful. I found a way to do it via a registry tweak.

If I go to HKEY_LOCAL_MACHINE/SOFTWARE/IBM/TPHOTKEY and create a key there called "8001" and inside that key I create a string called "File" that contains a path to a .exe I can then press that button to open said .exe

I made it so it would open my music app, Music Bee. It worked! Just one issue tho. The app opens in the background, and I have to click on it to bring it to the foreground, taking away from the convenience of the button. If I have to click on it to actually use it it's less useful. How can I make it open in the foreground? It opens in the background even when nothing else is open, so I have to click on it to make it the active window every time. This seems to happen with every program. Thanks.

Tomás Ralph

Posted 2020-02-22T00:29:05.693

Reputation: 11

You probably can't. If an app is started by a program not in the foreground then you can't steal focus if there is already a foreground process. The actual rules are here https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow. In the list of rules in Remarks you (ie the program) must comply with one of them to be able to set the foreground window.

– Mark – 2020-02-22T01:33:31.627

@Mark Interesting, however it mentions that it can become the foreground process if there's no foreground process. So, is there a way to move every process to the background then? That way no process should be in the foreground and this new one should become the new foreground process. – Tomás Ralph – 2020-02-22T02:28:17.917

@TomásRalph - You can minimize all application windows by shaking an application window on Windows but that really isn't what you want. Music Bee would have to be programmed to go to the foreground when it's launched. Based on the behavior you describe that does not appear to be the case. – Ramhound – 2020-02-22T03:42:42.020

If you minimise all programs NORMALY Explorer's Desktop gets the focus. Explorer supports hot keys. There are two types of hotkeys in Windows. One is system hotkey that a program registers (and so must be running) and there are hotkeys for Windows - the square things on your screen (but almost no programs uses them and the window has to be in existence). Setting a hotkey in a Shortcut on the Desktop or Start menu Explorer will start the shortcut, and if a window is created sets the other type of hotkey to the window. – Mark – 2020-02-22T04:27:14.063

References: System Hotkeys (to a program) https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey and Windows hotkeys (to a window) https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-sethotkey. Despite similar terminology they are completely different.

– Mark – 2020-02-22T04:31:16.180

Background: 1995 Windows 95 is released. Programs are sooooo slow starting (due to little memory) that users get bored waiting. Clicked solitaire and a minute later your program started interfering with solitaire. In Windows 98 restrictions came in to stop slow programs (and bad programs) from stealing focus. A program MUST show a window within 2 seconds of being starting and it will show in the foreground - over 2 seconds it depends on the user's actions. If the user clicks elsewhere it loses the ability to be in the foreground. Forums like this were filled with angry ranting people. – Mark – 2020-02-22T04:44:16.763

@Mark So basically, I can't do what I want. Nice to know, you gave me a lot of insight on how Windows manages... well, windows. It's cool to know all this and as I'm fairly young I never really used Windows 98 or 95 to know those problems existed. I did used them a bit on school because computers there are so old. Anyways, thanks for the help. – Tomás Ralph – 2020-02-23T04:55:29.067

However you can simulate system keys like Alt+Tab. So a two line VBScript program CreateObject("WScript.Shell).Run "notepad" and to send alt tab, send as many as you need. CreateObject("WScript.Shell").SendKeys "%{TAB}". For the above reason sendkeys is no longer as useful as it was. – Mark – 2020-02-23T06:05:57.557

@Mike So I change "notepad" to the process name of Music Bee? How could this actually work? I guess I would need to make it so the script runs at the same time I press the button which is something I can figure out on my own, but what would the script actually need to contain in order to work? – Tomás Ralph – 2020-02-23T06:45:08.237

There is no Mikes here. Depending on how the key software starts programs one or both of these will work. Firstly if it uses shell functions just the path and name to the vbs script will do. If it uses base functions then wscript "C:\MyVBSFile.vbs" Use full paths in everywhere, my example really should have been ("WScript.Shell).Run "C:\windows\notepad.exe" to make it bulletproof.. – Mark – 2020-02-23T18:38:09.607

The script need to contain the two lines I gave above. First line starts notepad. Second line send 1 x Alt+Tab. % means Alt, and {TAB} means, you guessed it, the Tabulation key. – Mark – 2020-02-23T18:50:08.173

Yeah sorry, I fucked up your name haha. Problem is, I deleted the wscript program because I virus was trying to open it to execute scripts. I never could remove the virus so I deleted the exe instead. Everytime I turn on the PC an error appears because it tries to open wscript but it's not there. The virus itself converted all the files on a removable storage into shortcuts, effectively deleting them. So I think I won't be able to use scripts without taking care of that first... but even registry tweaks were not able to. You don't need to help me anymore if you don't want, I'm really greateful – Tomás Ralph – 2020-02-24T05:14:00.720

No answers