我有一个提供给我的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)
答案 0 :(得分:1)
答案 1 :(得分:0)
我有类似的问题。
我的预定任务是在特定用户下运行的。使用MMC的组件服务管理单元我需要为用户提供“启动和激活”权限。完成此操作后,计划任务就会正确运行。
'CreateObject(“Scripting.FileSystemObject”)'行将需要我相信的这些权限。