开发者

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

开发者 https://www.devze.com 2023-03-24 00:14 出处:网络
I know how to execute a exe with wscript.exe, something like this: Set WshShell = WScript.CreateObject(\"WScript.Shell\")

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

精彩评论

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