General discussion


My Script Works Only In XP and Not In 2000

By svishwanathan ·
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.
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 I " & intJobID
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 sComputer & " No Response"
output.WriteLine sComputer & "---->" & "Offline" & "---->" & "Inventory Failed" & "---->" & errReturn
WScript.Echo sComputer & "---->" & "Offline" & "---->" & "Inventory Failed"
End If


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)
str = path
End If
StripDriveInfo = str
End Function

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Some things to check

by NickNielsen In reply to My Script Works Only In X ...

Do the all the machines have the same version of the VB runtime?

Are permissions set correctly?

Did you change the scripts to allow for any applicable differences between 2K and XP?

Are any system variables you are calling from the scripts the same between the two operating systems?

Collapse -

No Seperate Variables For Win 2K and Win XP

by svishwanathan In reply to Some things to check


I have not declared any variables for WinXP or Win2K. The script run's on Win XP but not on Win2K.

It is a domain environment hence the permissions are same for WinXP or Win2K.

Please help in resolving this conflict of Win2K and WInXP.

Collapse -

There are differences between Win2K and WinXP

by NickNielsen In reply to No Seperate Variables For ...

I think your script is running afoul of one of those differences. I'm not that good at scripting, so I don't know where the problem might be.

You would probably get a better response if you reposted this as a question (select "Ask a Question" from the Start A Discussion/Ask a question button at the top of the page).

Related Discussions

Related Forums