2022年5月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
無料ブログはココログ

« IsEmpty() などは使わないこと。 | トップページ | .NETでファイルを検索するときは、Directory.GetFiles(,検索パターン)を積極的に使うべし。 »

2008年4月23日 (水)

WScriptオブジェクトの簡単ラッパーオブジェクト

WScript.exeやCScript.exeのWScriptオブジェクトをVBやVBAから使うには、そのラッパオブジェクトを作ればよいのです。
まぁそこまでしなくても、手抜きのラッパーオブジェクト擬似なら簡単です。

WScript.VBS
---
Do While Not WScript.StdIn.AtEndOfStream
  Execute WScript.StdIn.ReadLine
Loop
---

WScript.exeを使うには、

Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("WScript.exe WScript.VBS")
oExec.StdIn.WriteLine "WScript.Echo 5000"
oExec.StdIn.WriteLine "WScript.Sleep 5000"
oExec.StdIn.WriteLine "WScript.Echo 5000"
oExec.StdIn.Close

CScript.exeを使うには、

Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("CMD /C CScript.exe WScript.VBS >CON")
oExec.StdIn.WriteLine "WScript.Echo 5000"
oExec.StdIn.WriteLine "WScript.Sleep 5000"
oExec.StdIn.WriteLine "MsgBox 5000"
oExec.StdIn.Close

« IsEmpty() などは使わないこと。 | トップページ | .NETでファイルを検索するときは、Directory.GetFiles(,検索パターン)を積極的に使うべし。 »