My Script Works Only In XP and Not In 2000 - TechRepublic
General discussion
October 24, 2009 at 09:06 AM
svishwanathan

My Script Works Only In XP and Not In 2000

by svishwanathan . Updated 16 years, 8 months ago

I have a vb script that initializes another vbscript in a remote computer. Now I have a issue…. this vb script initializes the script on the remote computer only if it is working has XP as the OS if the OS is 2000 then the script does not initialize. Please help. This is urgent.
———————————-
VB SCRIPT THAT IS USED TO INITIALIZE ON REMOTE COMPUTERS
———————————-
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

strComputer = sComputer
strCommand = “D:\UPSDATA\AssetScan.vbs”

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

output.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

This discussion is locked

All Comments