Created
May 3, 2012 14:32
-
-
Save ebibibi/2586011 to your computer and use it in GitHub Desktop.
[vbscript]add log message to file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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