cscript.exe opens a window
I have a vbs file that need to be run in 32-bit, even though I am running Windows 7 64-bit. I can launch this file with the command
and that works fine, but it leaves me with a redundant command prompt window that I have to close manually each time. It also makes it very cumbersome to run this vbs-file as a startup item.
Is there a way to start my 32-bit vbs-file in the background?
Try this for the 64bit problem, if it works you can combine it with the other answers
EDIT: here a question that goes more in depth on the 32/64 bit issue
here the modified version, should make sure the script runs on 64bit platform
On Error Resume Next Dim WshShell, OsType Set WshShell = CreateObject("WScript.Shell") OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE") If OsType = "x86" then wscript.echo "Windows 32bit system detected" else wscript.echo "Windows 64bit system detected" If InStr(LCase(WScript.FullName),"system32") Then CreateObject("WScript.Shell").Run """%systemroot%\SysWOW64\wscript.exe"" """ & WScript.ScriptFullName & """" Wscript.Quit End If end if Msgbox("I ran..")
If you need to use cscript this is IMHO a cool solution
Const HIDDEN_WINDOW = 0 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objStartup = objWMIService.Get("Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance_ objConfig.ShowWindow = HIDDEN_WINDOW Set objProcess = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process") objProcess.Create "Cscript.exe h:\Script\Test1.vbs", null, objConfig, intProcessID
If you can use wscript you could do the following, it's the simplest approach
Set objShell = CreateObject("Wscript.Shell") objShell.Run "Wscript.exe h:\Script\Test1.vbs"
actually you can do it as a one-liner (i'm a Ruby guy 8>)