VB错误“需要对象”

时间:2010-07-16 14:49:18

标签: vbscript

当我运行以下脚本时,我在第54行(最后一行)收到“需要对象”错误。有什么问题?

 Option Explicit
Dim cmdString, g_strHostFile, filepath, flexnetpath, importcmd, dtmToday, dtmYesterday, dtmFileDate, param1, param2, param3, i4path, objFSO, objTextStream, g_strComputer, WshShell
'Initialize global constants and variables.
Const FOR_READING = 1
g_strHostFile = "D:\dataimports\LUM_servers.txt"
i4path = "C:\IFOR\WIN\BIN\i4blt.exe"
filepath = "D:\DataImports\"
flexnetpath = "C:\Program Files (x86)\Flexnet\Manager\Admin"
importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath
dtmToday = Date()
dtmYesterday = Date() - 1
dtmFileDate = Year(Date) & padDate(Month(Date)) & padDate(Day(Date))
param1 = "-r1 -e2,4 -n "
param2 = " -v 'Dassault Systemes' -b "
param3 = " -g "
WScript.Echo "i4Path: " & i4path
WScript.Echo "FilePath: " & filepath
WScript.Echo "flexnetpath: " & flexnetpath
WScript.Echo "importcmd: " & importcmd
WScript.Echo "dtmToday: " & dtmToday
WScript.Echo "dtmYesterday: " & dtmYesterday
WScript.Echo "dtmFileDate: " & dtmFileDate

'Read LUM Server Names from text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(g_strHostFile) Then
  Set objTextStream = objFSO.OpenTextFile(g_strHostFile, FOR_READING)
Else
  WScript.Echo "Input file " & g_strHostFile & " not found."
  WScript.Quit
End If
'Loop through list of computers and perform tasks on each.
Do Until objTextStream.AtEndOfStream
  g_strComputer = objTextStream.ReadLine
WScript.Echo "Processing Server: " & g_strComputer
Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl"
WScript.Echo "Processing Command: " & cmdString
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmdString"
Loop
objTextStream.Close
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Processing Bulk Import: " & importcmd
WshShell.Run "importcmd"

Function padDate(intNumber)
 if intNumber <= 9 Then
  padDate = "0" & CStr(intNumber)
 Else
  padDate = CStr(intNumber)
 End If
End Function

2 个答案:

答案 0 :(得分:7)

当您有Set x = y之类的语句时,会引发所需的对象,其中x不是对象类型,而是简单类型(IntegerDoubleDate等)。我认为该行

Set cmdString = i4path & param1 & g_strComputer & param2 & ...

导致错误,我认为您所要做的就是删除Set语句。我认为字符串不是来自Object,因此不需要Set语句。

答案 1 :(得分:6)

我认为有一些问题。

 importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath

你可能需要一些空格:

 importcmd = flexnetpath & " flexnet bulkimport -uadmin -padmin -f " & filepath

Set仅用于对象,而不是字符串,因此应从此行中删除:

 Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl"

我很确定你要么

 WshShell.Run importcmd

或者

 WshShell.Run """" & importcmd & """"