M. Wood
M. Wood

Reputation: 21

How to open a exe with invisible window?

For example, I used this code in VBS to open a BAT in "mode invisible" (the window is invisible), but I wanted to try with a exe (chrome.exe) and it doesn't worked. It only works for BAT. I don't know how to programming in VBS :/. This is the code:

set objshell = createobject("wscript.shell")
objshell.run "chrome.exe",vbhide

Also, I tried use this code (that I founded in Google like other):

set args = WScript.Arguments
num = args.Count

if num = 0 then
WScript.Echo "Usage: [CScript | WScript] invis.vbs aScript.bat <some script arguments>"
WScript.Quit 1
end if

sargs = ""
if num > 1 then
sargs = " "
for k = 1 to num - 1
    anArg = args.Item(k)
    sargs = sargs & anArg & " "
next
end if

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False

But technically it's the same. I want to open a invisible window of a exe like chrome.exe (for example) and I don't know how to do it for a exe :/


Hi. Thanks for that. I used this code for IE and works:

Set IExp = CreateObject("InternetExplorer.Application")
Set WSHShell = WScript.CreateObject("WScript.Shell")
IExp.Visible = False
IExp.navigate "www.google.com.co"

But it doesn't work for Chrome, so I used this new code with Chrome like browser default:

Dim iURL 
Dim objShell

iURL = "www.google.com.co"

set objShell = CreateObject("WScript.Shell")
objShell.run(iURL),vbhide

But it doesn't work for Chrome :/. I'm reading in Google that Chrome creates different process like the base and each tab of the browser. When Chrome starts it always there 2 or 3 process "chrome.exe" in task manager. So how do I open a invisible window of Chrome? :(

Upvotes: 1

Views: 7611

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

The code does what you want it to do. However, if the executable/script you're running is just a launcher for some other executable/script the statement will hide only the launcher, not the launched program. To my knowledge it's not possible to influence the visibility of grandchild processes from VBScript.

Demonstration:

If you start Notepad from a VBScript like this:

CreateObject("WScript.Shell").Run "notepad.exe", 0, False

you'll get a hidden Notepad instance (you can see the process in the Task Manager's "Processes" tab).

Now create a batch script like this:

@echo off
start /wait notepad.exe

If you double-click that batch script you'll see two windows: one CMD window with the batch script, and a Notepad window.

However, if you run the batch script from a VBScript like this:

CreateObject("WScript.Shell").Run "C:\path\to\your.cmd", 0, False

only the Notepad window becomes visible, because the batch process is hidden.

Upvotes: 1

Related Questions