1

I am trying to run a program (In this case Internet Explore) hidden/invisible from a VB script.

I found a simple script for making batch files hidden, and tried it. It didn't seem to work as the program just popped up as normal.

Here is my code so far:

CreateObject("Wscript.Shell").Run "iexplore.exe",0,True

This runs the program iexplore.exe, but doesn't run it hidden/invisible.

I am also running this VBS file from a batch file which is hidden. The batch file simply does:

start Run.vbs

Codes of each script/batch file:

Batch File: Main file launching VBS file

@echo off
:start
start HideExecuteServerVBS.vbs (To Hide the ExecuteServerVBS.bat file when running)
timeout /NOBREAK /T 5
TASKKILL /IM iexplore.exe
timeout /NOBREAK /T 3
TASKKILL /IM iexplore.exe /F
timeout /NOBREAK /T 1800
goto start

HideExecuteServerVBS.vbs

CreateObject("Wscript.Shell").Run "ExecuteServerVBS.bat",0,True

ExecuteServerVBS.vbs

@echo off
C:\Windows\sysWOW64\csript.exe C:\Users\Admin\RunInternetProcess\vbscript.vbs

vbscript.vbs

Set ie = CreateObject("InternetExplorer.Application")

Is there a possible way to run a program invisible through a VB Script (Visual Basic Script)?

Imperial Knight
  • 51
  • 2
  • 2
  • 7

3 Answers3

2

So here's the deal, if you are receiving an ActiveX error, you most likely are trying to run this vbscript under a server. Server with a 64bit platform with lack of support for direct execution of 32bit vbscripts? Yeah? If so, here's what you need to do.

Make a batch file: ExecuteServerVBS.bat

C:\windows\sysWOW64\cscript.exe C:\path\to\your\vbscript.vbs

Put your vbscript code here:

vbscript.vbs

Set ie = CreateObject("InternetExplorer.Application")
'Go crazy 

And BOOM. You're done.

UPDATE

update the file ExecuteServerVBS.vbs

@echo off
C:\Windows\sysWOW64\cscript.exe C:\Users\Admin\RunInternetProcess\vbscript.vbs > errorlog.log

update the file vbscript.vbs

On Error Resume Next
Dim ie 
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
'Perform IE functions here......
If err.number <> 0 then wscript.echo err.number & ":" & err.description
Rich
  • 4,134
  • 3
  • 26
  • 45
  • So the code for the "ExecuteServerVBS.bat" would be "C:\windows\sysWOW64\script.exe C:\path\to\my\vbscript.vbs"? – Imperial Knight Mar 27 '14 at 22:41
  • So then code for the "ExecuteServerVBS.bat" would be "C:\windows\sysWOW64\cscript.exe C:\path\to\my\vbscript.vbs"? – Imperial Knight Mar 27 '14 at 22:53
  • Yes. No luck? Theres additional info on executing vbs on a aerver in the vbscript info page. – Rich Mar 27 '14 at 22:56
  • By the way, I'm not running a server. – Imperial Knight Mar 27 '14 at 22:59
  • For some reason, when it launches it opens a new tab in the browser I am currently in (Not Default browser, not internet explorer). – Imperial Knight Mar 27 '14 at 23:05
  • Full code of what? The VBS file or the main batch file running the VBS file? – Imperial Knight Mar 27 '14 at 23:09
  • Both, in your question please. – Rich Mar 27 '14 at 23:12
  • does vbscript.vbs = hideexecuteservervbs.vbs? – Rich Mar 27 '14 at 23:26
  • No, I will add the vbscript.vbs. Forgot it, sorry. – Imperial Knight Mar 27 '14 at 23:27
  • Ok cool. Update your files according to my instructions above and let me know the error description after you run it. If it runs successfully, let me know and i'll rewrite the above code so it runs quietly. – Rich Mar 27 '14 at 23:34
  • Says it successfully attached to the IE dll. – Imperial Knight Mar 27 '14 at 23:40
  • Still opens a new tab in this browser though. – Imperial Knight Mar 27 '14 at 23:41
  • It works when I do not have this browser open, but when I do it opens another tab. – Imperial Knight Mar 27 '14 at 23:44
  • Yeah it's going to do that if you don't specify that you want it as invisible. Let me update my code. one sec – Rich Mar 27 '14 at 23:47
  • Ok, try the code out in the section above. It should activate without opening a new tab. Make sure you keep the error handling in your code and it will output too errorlog.log after you update your batch file with my suggestion as well. And you should be good to go! – Rich Mar 27 '14 at 23:49
  • Now it works fine when I run the vbscript.vbs file directly, but not when I run the batch file that executes the ExecuteServerVbs.bat. – Imperial Knight Mar 27 '14 at 23:56
  • Yeah, most likely because the Shell.Run command doesn't like the command output i put in " > errorlog.log", if you remove that i'm sure it won't be a problem. Regardless, you got what you needed? Can I get a big green check mark FTW? :D – Rich Mar 27 '14 at 23:57
  • Removed the "> errorlog.log", but it still opens in a new tab =/ – Imperial Knight Mar 28 '14 at 00:23
  • I ran it and could not resimulate your issue. Are you trying to navigate the current iexplore session? – Rich Mar 28 '14 at 00:33
  • No, I am on another browser but it opens a new tab on that browser rather than opening Internet Explorer. – Imperial Knight Mar 28 '14 at 00:43
  • Yeah, maybe you should just not run a browser while your executing it then. No idea why it's triggering that for you. That's your machines problem for sure. I'm running lots of browsers as i'm currently designing websites and then did not happen with me. – Rich Mar 28 '14 at 01:04
1

You need to load it this way instead:

Set ie = CreateObject("InternetExplorer.Application")

' To make visible, uncomment the following line...
'ie.Visible = True
Bond
  • 16,071
  • 6
  • 30
  • 53