开发者

Execute a file in VBScript with cscript.exe and not wscript.exe

I know how to execute a exe with wscript.exe, something like this:

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run "c:\myprogram.exe"

But I'm forced to run my vbscript with cscript.exe, and can't use 开发者_运维技巧the WScript object. Are there any way to execute an exe when loaded with cscript.exe?


Both wscript.exe and cscript.exe provide the WScript object; so "Set WshShell = WScript.CreateObject(...)" is okay for .vbs files started with "w|cscript.exe whatever.vbs". VBScript - the language - provides its own CreateObject() function, so you can use plain "Set WshShell = CreateObject(...)" in all scripts (.hta, html too). The WScript COM object is another object. You can use it 'everywhere' (if we disregard security settings). In short: your code will work (or fail) with both hosts.


Set objShell = CreateObject("WScript.Shell")
objShell.run("cscript d:\Test2.vbs") 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜