'----------------------------------------------------------------------------
' 実行ホストを切り替える
'----------------------------------------------------------------------------
Sub cscript
SetScriptHost "cscript"
Set Debug = New TDebug
End Sub
Sub SetScriptHost(HostName)
If InStr(LCase(WSCript.FullName), LCase(HostName)) <> 0 Then Exit Sub
Dim i,s
s = HostName & " //nologo """ & WScript.ScriptFullName & """"
If WScript.Arguments.Count > 0 Then
For i = 0 To WScript.Arguments.Count -1
s = s &" """ & WScript.Arguments.Item(i) & """" ' 引数
Next
End If
CreateObject("WScript.Shell").Run s
WScript.Quit
End Sub
'----------------------------------------------------------------------------
' TDebugクラス
'----------------------------------------------------------------------------
Private Debug
' クラス
Class TDebug
Dim FEnabled
' 初期化処理
Private Sub Class_Initialize()
FEnabled = InStr(LCase(WSCript.FullName), "cscript") > 0
If FEnabled Then WScript.Echo Now & vbTab & WScript.ScriptFullName
End Sub
' 終了処理
Private Sub Class_Terminate()
If Not FEnabled Then Exit Sub
WScript.Echo Now & vbTab &" [END]"
WScript.StdIn.ReadLine
End Sub
' CScriptホストかどうか
Public Property Get Enabled
Enabled = FEnabled
End Property
Public Property Let Enabled(Value)
If FEnabled Then FEnabled = Value
End Property
' デバッグメッセージ処理
Public Sub Print(iStr)
If Not FEnabled Then Exit Sub
Dim stime
stime = Mid(Now,InStr(Now," ")+1,Len(Now))
WScript.Echo stime & vbTab & iStr
End Sub
End Class
'----------------------------------------------------------------------------
' dprintf(クラスを呼び出す)
'----------------------------------------------------------------------------
Sub dprintf(iStr)
If VarType(Debug) = vbEmpty Then
Set Debug = New TDebug
End If
Debug.Print(iStr)
End Sub
'----------------------------------------------------------------------------
' dprintf実行を終了する(スクリプト終了時にコンソールを残さない)
'----------------------------------------------------------------------------
Sub dprintf_end
If VarType(Debug) = vbObject Then
Debug.Enabled = False
End If
End Sub