Run browser on background - vbscript

I'm trying to open a browser with vbs program on background. My program code is this:
CreateObject("Wscript.Shell").Run "firefox.exe",0,True
The problem is that the window that opens isn't hidden. Also if I open any other program this way it runs on background eg. if I replace firefox.exe with notepad.exe. what's wrong? Thanks

Browsers often have many processes for UI and pages. It's likely the first firefox.exe only serves as a launcher, and it opens subsequent instances of firefox.exe that actually provides the UI. So unfortunately you can't hide the window with your current implementation.

Related

Close an application window without terminating in Command Line

Is there a command on the Windows terminal to close the window of an active application without actually killing the task/process?
What I'm looking for is something similar to clicking the 'X' button on the application window's name bar, or hitting Alt+F4 on it.
Any help would be greatly appreciated. Thanks!
I don't want the taskkill command because it terminates the process. I don't want it to terminate, say I want to close a Skype window so that it pops up in my Notification Tray on my Taskbar.
I couldn't find a specific command on the Windows terminal to do what I wanted, but I found this VBScript code online that did the trick for me.
set shell = createobject("wscript.shell")
shell.appactivate("Skype for Business")
shell.sendkeys "%{F4}"
This simulated an Alt+F4 keypress to Skype, which effectively closed the window and sent it to my Notification Tray.

Send keystrokes from vbscript to a CMD window

I run a batch file as part of Windows XP startup which executes continuously until Windows closes. It calls a VBScript file, which executes SendKeys "+{ESC}" (Shift+Esc). This gets picked up by 4t Tray Minimiser to send the CMD window to the system tray. Most times it works, but occasionally the CMD window stays visible.
Upon searching, various posts seem to suggest the .VBS file is losing focus or it's a timing problem. Some suggest AppActivate but I can't work out how to achieve what I want. Even the examples given for AppActivate seem like a lot of work.
Did you check the documentation? It's actually rather straightforward. You call AppActivate with the title (or part of the title) of the window you want to bring to the foreground, then run SendKeys to send keystrokes to the foreground window.
Set sh = CreateObject("WScript.Shell")
sh.AppActivate "window title"
sh.SendKeys "+{Esc}"

CreateProcess of console app, and get the main window handled

I am trying to write a program what will manage few console windows, my program will be able to CreateProcess() for new console windows, get a window main handle and the use that handle to resize, close, hide, change title etc. But I cannot find a reliable way to get a main window handle. The purpose is to have a tab bar and switch between created console windows with the click on the tab.
I have tried few ways:
1) use windows "cmd.exe" ability to set window title, and then FindWindow("tmp_title"...)
This has a problem, I do not need cmd.exe running, and also I need a processID for the target program not the cmd.exe. Maybe I should use this way but check for children subprocesses?
2) EnumWindows() then CreateProcess() then wait 40 ms, then EnumWindows() again and find the new window.
This is unreliable! I got two new windows sometimes for weird reasons.
3) use GetWindowThreadProcessId() + EnumWindows(). This worked the best on XP, but on win7 the found window seems to be the wrong one, it's GetWindowText() returns "DefaultIME" and hide/show of this window does nothing. So it is obviously a wrong one.
So any idea how to do it reliably and if possible cross-platform (Cross-windows, XP,Vista,7)

Why does the safari app gets launched when I open apple script?

I have an applescript. The script goes like this..
tell application "Safari"
open location "http://www.google.com" -- mentions the perticular webpage to be loaded
activate --makes the Safari application the front most application
end tell
Whenever I open this script, the Safari application gets launched. To be very clear, I'm not running this application instead I am just opening this script in applescript editor.
Can anyone please explain me why the Safari is getting launched. The Safari gets launched but it will be hidden or say it does not put up any window. [Neither it does load any pages in the background, it just gets launched in the dock and a dot saying that the app is launched will be present].
Once I run the script then the safari puts up the window and loads the desired web-page.
Please Help.
In general, applescript must launch an application to learn what commands it understands. Over time applescript has gotten better at not launching applications for this task, but some apps still get launched. iPhoto is one I notice gets launched when I open applescripts that use it. As such it's not something you can avoid.
However, in your case there may be a fix. The "open location" command is a generic applescript command. You do not need to tell Safari to execute that command. Therefore you can probably change your script to this and avoid the launching issue. The open location command should just open the link in your default browser which I assume in your case is Safari. It should also automatically activate it for you.
Good luck.
open location "http://www.google.com"

Create a background process in windows

How do I make a process go the background programatically?
What I want is for the user to double-click the process executable, and it just goes into the background ... and does not open a window while executing.
Any code snippet in visual c++ would be very helpful
Have you considered creating a Windows Service instead? They're specifically designed to run in the background without showing a UI.
Otherwise, just create an application without a window.
I know this is old, but I thought I would post something for when people find this through search.
While I like Cody Gray's answer for design correctness, sometimes you don't have a choice.
If you want to launch a program without jumping to the new window (it appears in the background or minimized) or not create a window at all try looking at the ShellExecute and ShellExecuteEx functions. The argument nShowCmd (or nShow) gives you (among others) the options:
SW_HIDE
Hides the window and activates another window.
SW_SHOWMINNOACTIVE
Displays the window as a minimized window. The active window remains active.
As the documentation says, SW_HIDE creates a process running the executable you give it, but if this program would normally create a window, none appears.
This might help: http://ss64.com/nt/start.html
I tried this way and it worked fine:
Create a console application and write your codes in the sub main as any other console application.
Now change the application type in the project properties to windows Forms application from Console application
thats it

Resources