General discussion
Thread display: Collapse - |
All Comments
Start or search
Create a new discussion
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
My Script Works Only In XP and Not In 2000
----------------------------------
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 I
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