win 2008中的任务调度程序不会运行vbs脚本

时间:2012-07-11 07:18:03

标签: vbscript batch-file task scheduler

我有一个批处理文件,它调用vbs脚本如下:

cd d:
    cd D:\Application\Pentasafe\HKPentasafe\DailyLog\Deployment Code
    cscript CommandProcessing.vbs
    del /s "D:\Application\Pentasafe\HKPentasafe\DailyLog\Command Usage by Command\Tempworkspace\*.txt"

此批处理文件调用此vbs(命令处理),然后将删除tempworkspace中的文件

Const ForReading = 1
Const ForWriting = 2

Dim Source, Dest

objStartFolder = "D:\Application\Pentasafe\HKPentasafe\DailyLog\Command Usage by Command\Tempworkspace"
objDestFolder = "D:\Application\Pentasafe\HKPentasafe\DailyLog\Command Usage by Command\Scripted"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files

'Only one file expected.
For Each objFile in colFiles
    Source = ObjStartFolder + "\" + objFile.Name
    Dest = ObjDestFolder + "\" + objFile.Name
    wscript.echo Source
    wscript.echo Dest
Next

Set objFile = objFSO.OpenTextFile(Source, ForReading)

Set objFile1 = objFSO.CreateTextFile(Dest, ForWriting)

Do Until objFile.AtEndOfStream
    Strline = objFile.ReadLine
    'wscript.echo Strline

    If InStr(Strline,"CHGUSRPRF") Then
    Prependtext = "CHGUSRPRF"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline,"STRSQL") Then
    Prependtext = "STRSQL"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline,"STRDFU") Then
    Prependtext = "STRDFU"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline,"UPDATA") Then
    Prependtext = "UPDATA"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline,"EZVIEW") Then
    Prependtext = "EZVIEW"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline,"WRKQRY") Then
    Prependtext = "WRKQRY"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline,"WRKUSRPRF") Then
    Prependtext = "WRKUSRPRF"
    wscript.echo Strline
    objFile1.WriteLine Strline
    ElseIf InStr(Strline, "             ") Then
    If (Prependtext <> "") Then
        objFile1.WriteLine Replace(Strline, "             ", Prependtext)
        wscript.echo Replace(Strline, "             ", Prependtext)
    else
        objFile1.WriteLine Strline   
    End If
    Else 
    Prependtext = ""
    objFile1.WriteLine Strline
    End If
Loop

objFile.Close
objFile1.Close

但是,当我在窗口服务器2008中安排此作业时...它始终不会调用vbs脚本。而是跳过它然后做删除工作。 我尝试通过双击批处理文件手动运行它。 它在窗口xp中运行良好,直到我们升级到窗口服务器2008.任何人对此主题有任何想法?

2 个答案:

答案 0 :(得分:1)

批处理文件运行时的当前驱动器是什么?很可能是C:驱动器。由于您未将D:设置为当前驱动器,因此将找不到CommandProcessing.vbs。要修复它,请将其更改为D:CommandProcessing.vbs或使D:当前驱动器。

答案 1 :(得分:0)

CommandProcessing.vbs文件在哪里?

在D:\ Application \ Pentasafe \ HKPentasafe \ DailyLog \ Deployment Code?

可能cd命令失败,因为第一行中的路径不在qoutes中。然后cscript找不到脚本文件。