Vbscript 自动导入脚本不工作

Vbscript 自动导入脚本不工作,vbscript,Vbscript,我是VB的绝对初学者,因此我可能会问一些愚蠢的问题。 我有一个VB脚本通过一个批处理文件触发,该文件导致最后一天导入数据。 下面是VB和批处理文件的代码。 如果您看到代码中有任何错误,请告诉我 VB脚本 rem rem XLink_Import.vbs rem Set oShell = WScript.CreateObject("WScript.Shell") ' filename = oShell.ExpandEnvironmentStrings("today_xlink.bat")

我是VB的绝对初学者,因此我可能会问一些愚蠢的问题。
我有一个VB脚本通过一个批处理文件触发,该文件导致最后一天导入数据。 下面是VB和批处理文件的代码。
如果您看到代码中有任何错误,请告诉我

VB脚本

rem 
rem XLink_Import.vbs
rem 

Set oShell = WScript.CreateObject("WScript.Shell") 

' filename = oShell.ExpandEnvironmentStrings("today_xlink.bat") 
' Set objFileSystem = CreateObject("Scripting.fileSystemObject") 
' Set oFile = objFileSystem.CreateTextFile(filename, TRUE) 

Dim i
Dim ImportStartOffset, ImportedNumberOfDays

If WScript.Arguments.length > 0 Then
    For i=0 to WScript.Arguments.length-1
        Arg = WScript.Arguments(i)
        If Left(Arg,1) = "-" Then
            If ( Arg = "-o" ) Then
                ImportStartOffset = WScript.Arguments(i+1) 
            End if
            If ( Arg = "-n" or Arg = "-l" ) Then
                ImportedNumberOfDays = WScript.Arguments(i+1) 
            End if
        End if
    Next
End If

rem Prepare the import start date

Dim Dy, Mth
Dim ImportDate
ImportDate = Now + ImportStartOffset
Dy = Day(ImportDate) 
Mth = Month(ImportDate) 
If Len(Dy) = 1 Then Dy = "0" & Dy 
If Len(Mth) = 1 Then Mth = "0" & Mth 
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate) 

rem Prepare import script to run (not useed yet)
rem oFile.WriteLine("isps_ul.exe -t -d " & todaydate & " -L 1") 
rem oFile.Close

rem Run XLink import

wscript.echo "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays
oShell.Run "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays, 1, true
批处理文件

@echo off
rem
rem XLink_Import.bat
rem
rem Manually starts an Xlink import starting today + a StartOffset of some days. 
rem Imported number of days can also be set.
rem

set ImportStartOffset=0
set ImportedNumberOfDays=1

cscript XLink_Import.vbs -o %ImportStartOffset% -n %ImportedNumberOfDays%

pause

你不需要一个批处理和一个脚本,其中一个就足够了,在批处理中做整个事情需要一些特殊参数的提示,我不喜欢这样,所以我会调整你的脚本,如下所示。 由于您将2个配置变量保存在windows环境中,因此也可以从vbscript中读取它们,其他选项是从配置文件中读取,就像从命令行读取一样,或者将变量保存在脚本本身中

如果在配置(环境变量)中正确设置了这些日期,则可以省略中间部分,以确保日期正确

如果导入工作正常,您应该在运行显示为命令的内容之前进行检查,因此,例如,应运行eisps_ul.exe-t-d28/11/2016-L“,否则应首先搜索该问题

我在评论中所说的“保持干燥”的意思是,您不应该重复操作,在使用命令的情况下,您可以将连接的命令存储在一个变量中,并将其用于查看和运行

Dim ImportStartOffset, ImportedNumberOfDays, oShell, command, Dy, Mth, ImportDate, ImportStartDate
Constant WaitOnReturn = true, WindowStyle = 1 '1 = Activate and display

'read configuration environment variables
Set oShell           = CreateObject( "WScript.Shell" )
ImportStartOffset    = wshShell.ExpandEnvironmentStrings( "%ImportStartOffset%" )
ImportedNumberOfDays = wshShell.ExpandEnvironmentStrings( "%ImportedNumberOfDays%" )

'Prepare the import start date (not necessary if environmentvariables would be configured well)
ImportDate = Now + ImportStartOffset
Dy = Day(ImportDate) 
Mth = Month(ImportDate) 
If Len(Dy) = 1 Then Dy = "0" & Dy 
If Len(Mth) = 1 Then Mth = "0" & Mth 
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate) 

'Run XLink import
command = "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays
wscript.echo command
oShell.Run command, WindowStyle, WaitOnReturn
Set oShell = Nothing

你不需要一个批处理和一个脚本,其中一个就足够了,在批处理中做整个事情需要一些特殊参数的提示,我不喜欢这样,所以我会调整你的脚本,如下所示。 由于您将2个配置变量保存在windows环境中,因此也可以从vbscript中读取它们,其他选项是从配置文件中读取,就像从命令行读取一样,或者将变量保存在脚本本身中

如果在配置(环境变量)中正确设置了这些日期,则可以省略中间部分,以确保日期正确

如果导入工作正常,您应该在运行显示为命令的内容之前进行检查,因此,例如,应运行eisps_ul.exe-t-d28/11/2016-L“,否则应首先搜索该问题

我在评论中所说的“保持干燥”的意思是,您不应该重复操作,在使用命令的情况下,您可以将连接的命令存储在一个变量中,并将其用于查看和运行

Dim ImportStartOffset, ImportedNumberOfDays, oShell, command, Dy, Mth, ImportDate, ImportStartDate
Constant WaitOnReturn = true, WindowStyle = 1 '1 = Activate and display

'read configuration environment variables
Set oShell           = CreateObject( "WScript.Shell" )
ImportStartOffset    = wshShell.ExpandEnvironmentStrings( "%ImportStartOffset%" )
ImportedNumberOfDays = wshShell.ExpandEnvironmentStrings( "%ImportedNumberOfDays%" )

'Prepare the import start date (not necessary if environmentvariables would be configured well)
ImportDate = Now + ImportStartOffset
Dy = Day(ImportDate) 
Mth = Month(ImportDate) 
If Len(Dy) = 1 Then Dy = "0" & Dy 
If Len(Mth) = 1 Then Mth = "0" & Mth 
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate) 

'Run XLink import
command = "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays
wscript.echo command
oShell.Run command, WindowStyle, WaitOnReturn
Set oShell = Nothing

运行脚本时是否出现错误?如果是,在哪一行,在哪一行?为什么批处理,您可以在脚本本身中进行配置,或者使用命令行中的参数进行配置?您还应该将运行字符串分配给一个要执行的变量。您好@peter-感谢您的回复,不,我没有收到错误,我收到消息“ISP_ul.exe-t-d28/11/2016-L”使用批处理的原因是我想自动执行此任务,我知道的唯一方法是使用windows任务计划程序。很抱歉,我理解执行此任务的部分(请原谅我的无知,我才刚开始)运行脚本时是否出现错误?如果是,哪一行以及在哪一行?为什么是批处理,您可以在脚本本身中进行配置或使用命令行中的参数进行配置?您还应该将运行字符串分配给一个变量以使其干燥。您好@peter-感谢您的回复,不,我没有收到错误,我收到了消息“isps_ul.exe-t-d28/11/2016-L”使用批处理的原因是我想自动化此作业,我知道的唯一方法是使用windows任务计划程序。很抱歉,我理解其中的枯燥部分(请原谅我的无知,我刚刚开始)您好@peter,非常感谢您的帮助,我将尝试将此合并到代码中。您好@peter,非常感谢您的帮助,我将尝试将此合并到代码中。