Skip to content

Instantly share code, notes, and snippets.

@ebibibi
Created May 3, 2012 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebibibi/2586011 to your computer and use it in GitHub Desktop.
Save ebibibi/2586011 to your computer and use it in GitHub Desktop.
[vbscript]add log message to file.
AddLog "test", "c:\tmp\hoge.txt"
AddLog "test2", "c:\tmp\hoge.txt"
'-------------------------------------------------------------------------------------------
' 特定のファイルへのログ出力
'-------------------------------------------------------------------------------------------
' strMessage - 出力する文字列
' strTargetFile - 出力対象ファイル
'-------------------------------------------------------------------------------------------
Sub AddLog(strMessage, strTargetFile)
On Error Resume Next
Const ForAppending = 8 ' 追記モード
Dim fso, fi
Set fso = CreateObject("Scripting.FileSystemObject")
'ファイルを開く
'もしも存在しない場合には作成する
Set fi = fso.OpenTextFile(strTargetFile, ForAppending, true)
strMessage = Date() & " " & Time() & ": " & strMessage
fi.WriteLine (strMessage) 'ログを書き込む
Set fi = Nothing
If Err.Number <> 0 Then
Wscript.Echo "ログ出力中にエラーが発生しました。ログの出力先、権限等を確認してください。"
WScript.Echo "エラー : " & Err.Number & vbCrLf & Err.Description
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment