netshコマンドでIPアドレスを設定した時、その出力結果をファイルに保存したいと思った。
=====================================================
Set debugfso = CreateObject("Scripting.FileSystemObject")
Set debugf = debugfso.OpenTextFile("c:\\debug.txt", 8)
NETSHCMD = "netsh interface ip set address ~"
Set ObjExec = WshShell.Exec(NETSHCMD)
Do While objExec.Status = 0
WScript.Sleep 100
Loop
If Not ObjExec.StdErr.AtEndOfStream Then
set Results=ObjExec.StdErr.ReadAll()
debugf.WriteLine(Results)
ElseIf Not ObjExec.StdOut.AtEndOfStream Then
set Results=ObjExec.StdOut.ReadAll()
debugf.WriteLine(Results & " ")
End If
Set objExec = Nothing
debugf.Close
=====================================================
これだと、エラーになった。
具体的には「set Results=ObjExec.StdOut.ReadAll()」の部分。
以下の様に変えたらうまくいった
=====================================================
Set debugfso = CreateObject("Scripting.FileSystemObject")
Set debugf = debugfso.OpenTextFile("c:\\debug.txt", 8)
NETSHCMD = "netsh interface ip set address ~"
Set ObjExec = WshShell.Exec(NETSHCMD)
Do While objExec.Status = 0
WScript.Sleep 100
Loop
Do While Not ObjExec.StdErr.AtEndOfStream
debugf.WriteLine(ObjExec.StdErr.ReadAll)
Loop
Do While Not ObjExec.StdOut.AtEndOfStream
debugf.WriteLine(ObjExec.StdOut.ReadAll)
Loop
Set objExec = Nothing
debugf.Close
=====================================================