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

C:\Windows\SysWOW64\cscript.exe my-file.vbs

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

How do I check if wscript/cscript runs on x64 host OS?

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"
  wscript.echo "Windows 64bit system detected"
  If InStr(LCase(WScript.FullName),"system32") Then 
    CreateObject("WScript.Shell").Run """%systemroot%\SysWOW64\wscript.exe"" """ & WScript.ScriptFullName & """" 
  End If 
end if

Msgbox("I ran..")

If you need to use cscript this is IMHO a cool solution


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>)

CreateObject("Wscript.Shell").Run("Wscript.exe h:\Script\Test1.vbs")

Need Your Help

Best way to maintain reference to data needed throughout iOS app

ios objective-c properties reference

I have a number of view controllers embedded in navigation hierarchies and tab bar controllers. What is similar across all of the view controllers is that they all need to access the same data obje...