Script Execution Mode


Windows Scripting Host supports two modes of script execution - console and windowed. Quite often the scripts require access to stdio and therefore they should be run through cscript.exe. If they are running through wscript.exe it will cause an error.

To avoid this error, use the following code to force usage of CSCRIPT.EXE:

sub force_cscript    
	dim args : args=""    
	dim i, wshshell    	
	If right(lCase(wscript.fullname),11)= "wscript.exe" then        
		for i=0 to wscript.arguments.count-1            
			args = args & wscript.arguments(i) & " "        
		next        
		set wshshell=createobject("wscript.shell")        
		wshshell.run wshshell.ExpandEnvironmentStrings("%comspec%") & _
	            " /c cscript.exe //nologo """ & wscript.scriptfullname 
			& """" & args    'change to /k for stay
	        set wshshell=nothing        
		wscript.quit    
	end if
end sub

ScriptCryptor allows you to specify the execution mode at compile time so the above code is no longer needed. Moreover, it will cause an error of execution because it will attempt to execute an EXE file instead of the VBS.


Execution mode can be selected in the Settings window of the project before compilation.