提供された VBS ファイルに小さな変更を加えました。スクリプトをダブルクリックすると正常に実行されますが、スケジュールされたタスクとして実行するように設定されている場合、ステータスは「実行中」のままです。通常、タスクは数秒で完了します。
これがなぜなのか誰にも示唆できますか?
ありがとう
wscript.echo "VBScript Create_TaxiCheck_File"
Const InputFile = "C:\TaxiCheckLive\TaxiCheck_Data.txt"
Const OutputFile = "C:\TaxiCheckLive\TaxiCheck_Formatted.txt"
Const CSVFile = "C:\TaxiCheckLive\ChelmsfordExtract.csv"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim fso
Dim I
Dim IF1
Dim OF1
Dim InputLine
Dim Outputline
Dim comma
Set fso = CreateObject("Scripting.FileSystemObject")
'check input file exists
if (fso.fileexists(InputFile)) then
wscript.echo "Input file exists: " & InputFile
'Write to log file (File exists)
Set LogFile = fso.OpenTextFile("LogFile.txt", ForAppending)
LogFile.WriteLine DateInfo & Now & " - OK, Input file exists"
LogFile.close
Else
'Write to log file (File does not exist)
Set LogFile = fso.OpenTextFile("LogFile.txt", ForAppending)
LogFile.WriteLine DateInfo & Now & " - Error, input file does not exist, database export has not run!" & VbCrLf
LogFile.close
wscript.Quit(9)
end if
'if exists then delete output file
if (fso.fileexists(OutputFile)) then
wscript.echo "Deleting file: " & OutputFile
Set OF1 = fso.GetFile(OutputFile)
OF1.Delete
end if
'create output file
wscript.echo "Creating output file: " & OutputFile
Set OF1 = fso.CreateTextFile(OutputFile, True)
OF1.Close
'if exists then delete CSV file
if (fso.fileexists(CSVFile)) then
wscript.echo "Deleting file: " & CSVFile
Set OF1 = fso.GetFile(CSVFile)
OF1.Delete
end if
'create formated output file.
wscript.echo "Create formated output file."
Set IF1 = fso.OpenTextFile(InputFile, ForReading)
Set OF1 = fso.OpenTextFile(OutputFile, ForWriting)
Outputline = "MODE,VEH_REG_NO_NO_SPACES,VEH_MAKE,VEH_MODEL,VEH_COLOUR,LIC_NUMBER"
OF1.WriteLine Outputline
Outputline = "D,*"
OF1.WriteLine Outputline
Outputline = ""
Do While Not IF1.AtEndOfStream
InputLine = IF1.ReadLine
Outputline = "I," + InputLine
OF1.WriteLine Outputline
Outputline = ""
Loop
'copy output file to CSV file
fso.CopyFile OutputFile, CSVFile
'close input and output files
IF1.Close
OF1.Close
'delete input and output files
Set OF2 = fso.GetFile(InputFile)
OF2.Delete
Set OF3 = fso.GetFile(OutputFile)
OF3.Delete
'ftp file to firmstep ftp site
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("%windir%\system32\ftp.exe -s:C:\TaxiCheckLive\ftpcommands.txt")
wscript.echo "VBScript Create_TaxiCheck_File Ended Successfully"
'Write to log file (complete)
Set LogFile = fso.OpenTextFile("LogFile.txt", ForAppending)
LogFile.WriteLine DateInfo & Now & " - Script completed running" & VbCrLf
LogFile.close
wscript.Quit(1)