Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing CScript 2

Status
Not open for further replies.

acl03

MIS
Jun 13, 2005
1,077
0
0
US
Is there a way to force a script to run in CScript, even if it is simply double-clicked from windows explorer?



Thanks,
Andrew
 
To change the default scripting engine from WScript to CScript, type the following command at a system prompt:

C:\> cscript //h:cscript //s

To switch back to WScript as the default, use the following command:

C:\> cscript //h:wscript //s
 
I meant a way in the program itself, not in windows. I feel like I've seen this posted in TekTips before - can't find it though.

I've also seen a post explaining how to make a small IE window pop up to give status messages to user but I can't find that one either!



Thanks,
Andrew
 
This is what I use in my scripts to force CSCRIPT
CMD window visible
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
WScript.Quit
End If

I usually run this with the CMD window visible, but you can change the 1 to a 0 if you want it to remain hidden.
CMD window hidden
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
oShell.Run "cscript """ & WScript.ScriptFullName & """", 0, False
WScript.Quit
End If
 
This is what I use:

Code:
[gree]'********************
'Force Script to run using CSCRIPT
'********************[/green]
Dim oShell
Set oShell = CreateObject("Wscript.Shell")

forceUseCScript

Sub forceUseCScript()
   If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
      oShell.Popup "Launched using wscript. Relaunching...",3,"WSCRIPT"
      oShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34),1,False
      WScript.Quit 0
   End If
End Sub

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top