locked
VBScript Does Not Run In Windows 2000 But Runs In Windows XP RRS feed

  • Question

  • Hi,

    I have a vbscript that runs successfully in Windows XP but not in Windows 2000. Please help in getting the things. right.

    The script copy's a vbscript file to the workstations listed in a text file and then executes the script copied to the workstations remotely. This works well for Windows but not for Windows 2000. Please help
    ____________________________________________________________________________________________________________________________

    Option Explicit
    On Error Resume Next

    Dim oFSO, sCList, sComputer, sWinDir, colOperatingSystems, oOperatingSystem, strComputer, intJobID, strCommand
    Dim oWMIService, Error, sWinDirRaw, fso, drv, str, objWMIService, objSWbemDateTime, objScheduledJob, errReturn

    Const INTERVAL = "n"
    Const MINUTES = 1
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    Const PATH_TO_INPUT = "D:\UPSDATA\Asset\HostNames.txt"
    Const PATH_TO_OUTPUT = "D:\UPSDATA\Asset\Status.txt"
    Const ForReading = 1
    Const OverwriteExisting = True

    Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")

    Dim shl
    Set shl = WScript.CreateObject("WScript.Shell")
    Set sClist = oFSO.OpenTextFile(PATH_TO_INPUT)
    Dim output
    Set output = oFSO.CreateTextFile(PATH_TO_OUTPUT, True)

    output.WriteLine "Hostname---->Status---->Scan"

    Dim exec
    Dim pingResults
    While Not sClist.AtEndOfStream
     sComputer = sClist.ReadLine
     Set exec = shl.exec("ping -n 5 -w 1000 " & sComputer)
     pingResults = LCase(exec.StdOut.ReadAll)
     
     If InStr(pingResults, "reply from") Then
      WScript.Echo "Reply From: " & sComputer
      'On Error Resume Next

       'If hosts exists, rename to hosts_old -----------------------------------------
       If oFSO.FileExists("\\" & sComputer & "\D$\UPSDATA\AssetScan.vbs") Then
           oFSO.CopyFile "\\" & sComputer & "\D$\UPSDATA\AssetScan.vbs", "\\" & sComputer & "\D$\UPSDATA\AssetScan_old.vbs", OverwriteExisting
       End If
       'Copy Hosts file ---------------------------------------------------------------
        oFSO.CopyFile "D:\UPSDATA\Asset\AssetScan.vbs", "\\" & sComputer & "\D$\UPSDATA\", OverwriteExisting 
       
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
       Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
       Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

       objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
       errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)

       If errReturn = 0 Then
       Wscript.Echo "Scan was started with a process ID: " & intJobID
       Else
       Wscript.Echo "Scan could not be started due to error: " & errReturn
       End If
       WScript.echo "Inventory Scan Initiated : " & " on " & sComputer
       
       soutput.WriteLine sComputer & "---->" & "Online" & "---->" & "Inventory Done" & "---->" & errReturn
       WScript.Echo sComputer & "---->" & "Online" & "---->" & "Inventory Done"
       WScript.Echo"------------------------------------------------------------------------------"
     Else
       WScript.Echo sComputer & " No Response" 
       output.WriteLine sComputer & "---->" & "Offline" & "---->" & "Inventory Failed" & "---->" & errReturn
       WScript.Echo sComputer & "---->" & "Offline" & "---->" & "Inventory Failed"
       WScript.Echo"------------------------------------------------------------------------------"
     End If
    Wend
    output.Close
    sClist.Close

    Set oWmiService = Nothing

    WScript.Echo "Finished Inventory File Update on all computers"
    MsgBox ("Exit?")

    Function StripDriveInfo(path)
     'Set fso = CreateObject("Scripting.FileSystemObject")
     drv = oFSO.GetDriveName(path)
     If Len(drv) >0 Then
      str = Mid(path, Len(drv) + 2)
     Else
      str = path
     End If
     StripDriveInfo = str
    End Function

    Friday, December 25, 2009 8:41 AM

Answers

  • SWbemDateTime object is not available in Windows 2000 so you will need to construct the WMI datetime string to pass to Win32_ScheduledJob.Create() by yourself. You can find a sample here (listing 6.21), but you also need to add code for the time part.
    Uros Calakovic
    • Marked as answer by IamMred Saturday, January 16, 2010 7:39 AM
    Friday, December 25, 2009 3:39 PM
  • Also, the wshShell.Exec method requires WSH 5.6. This version comes with XP and above. Windows 2000 comes with WSH version 5.1, but version 5.6 can be installed. Or, you can use another method to ping, as per this link:

    http://www.rlmueller.net/PingComputers.htm

    Richard Mueller


    MVP ADSI
    • Marked as answer by IamMred Saturday, January 16, 2010 7:39 AM
    Saturday, December 26, 2009 12:09 AM

All replies

  • SWbemDateTime object is not available in Windows 2000 so you will need to construct the WMI datetime string to pass to Win32_ScheduledJob.Create() by yourself. You can find a sample here (listing 6.21), but you also need to add code for the time part.
    Uros Calakovic
    • Marked as answer by IamMred Saturday, January 16, 2010 7:39 AM
    Friday, December 25, 2009 3:39 PM
  • Also, the wshShell.Exec method requires WSH 5.6. This version comes with XP and above. Windows 2000 comes with WSH version 5.1, but version 5.6 can be installed. Or, you can use another method to ping, as per this link:

    http://www.rlmueller.net/PingComputers.htm

    Richard Mueller


    MVP ADSI
    • Marked as answer by IamMred Saturday, January 16, 2010 7:39 AM
    Saturday, December 26, 2009 12:09 AM