Run any application in background

2020-05-07 19:55发布

问题:

Again a VBScript problem.

Here is a working code

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run """C:\Program Files\TrueCrypt\TrueCrypt.exe""", 0 , false 

This runs the truecrypt on the background perfectly, but the code is highly unstable. If I substitute the path for itunes, wmplayer it fails.

Is there a code, which can completely run all types of programm hidden?

回答1:

.Run starts a console ('DOS Box') to execute some other process/program. You can control the display mode of that console (e.g. hide it by passing SW_HIDE == 0 as param 2), but what this other program does to your screen is up to this process. Programs meant to be executed silently (should) accept arguments like --headless or /nogui, or (should) provide a suitable IPC (e.g. COM) interface. So how to start other programs 'in the background' can't be answered in a 'one strategy for all' way. AFAIK, the players offer COM/OCX interfaces, and using these certainly beats Sendkeys voodoo. So google for "iTunes.Application vbscript" or "Wmplayer.OCX." to get some hints about how to use these COM objects.



回答2:

Instead of using the Shell Run method you could try the Create method of the WMI Win32_Process provider.
The example on this MSDN page creates a configuration object to set the process option ShowWindow to SW_NORMAL (i.e. 1) for a GUI executable - NOTEPAD.EXE.
On this page it looks like SW_HIDE (with a value of 0) is also an option.



标签: vbscript