Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VB script just keeps looping and does not excute the code

Reply
 
Old 02-06-2009   #1 (permalink)
freddy


 
 

VB script just keeps looping and does not excute the code

Here is the code :

On Error Resume Next
Const ForReading = 1
'Create FSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Read Text File
Set objFile = objFSO.OpenTextFile("U:\Scripts\PST\4fl_segment.txt",
ForReading)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Do Until objFile.AtEndOfStream
strcomputer = objFile.ReadLine

'**************************************** Start Ping
*******************************************
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address ='" & strcomputer & "'")
'WScript.Echo strcomputer & " Reply Received"
For Each objItem In colItems
If objItem.StatusCode = 0 Then
'***********************************************************************************************
'get ost files
Set colFiles = objWMIService.ExecQuery _
("Select Name from CIM_DataFile" _
& " where Drive='C:' and Extension='OST'")
'WScript.Echo "# of files found: " & colFiles.Count
For Each objFile in colFiles
Wscript.Echo strcomputer
Wscript.Echo objFile.Name
Next
Else
Wscript.Echo strcomputer & " No Reply"
End If
Next
Loop
objFile.Close

It reads the text file but does not excute the 'get ost files. It does work
when I use my local machine. Please help me

My System SpecsSystem Spec
Old 02-06-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: VB script just keeps looping and does not excute the code


"freddy" <freddy@xxxxxx> wrote in message
news:80F6CC5B-8FFA-4343-A159-E827347190C3@xxxxxx
Quote:

> Here is the code :
>
> On Error Resume Next
> Const ForReading = 1
> 'Create FSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> 'Read Text File
> Set objFile = objFSO.OpenTextFile("U:\Scripts\PST\4fl_segment.txt",
> ForReading)
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
> Do Until objFile.AtEndOfStream
> strcomputer = objFile.ReadLine
>
> '**************************************** Start Ping
> *******************************************
> Set colItems = objWMIService.ExecQuery _
> ("Select * from Win32_PingStatus " & _
> "Where Address ='" & strcomputer & "'")
> 'WScript.Echo strcomputer & " Reply Received"
> For Each objItem In colItems
> If objItem.StatusCode = 0 Then
> '***********************************************************************************************
> 'get ost files
> Set colFiles = objWMIService.ExecQuery _
> ("Select Name from CIM_DataFile" _
> & " where Drive='C:' and Extension='OST'")
> 'WScript.Echo "# of files found: " & colFiles.Count
> For Each objFile in colFiles
> Wscript.Echo strcomputer
> Wscript.Echo objFile.Name
> Next
> Else
> Wscript.Echo strcomputer & " No Reply"
> End If
> Next
> Loop
> objFile.Close
>
> It reads the text file but does not excute the 'get ost files. It does
> work
> when I use my local machine. Please help me
The first step is to remove the "On Error Resume Next" statement, so you get
an error message to help troubleshooting. A quick glance show that the code
redefines objFile. In the loop where you read lines of objFile, the object
reference is redefined to be one of the files on a computer. Maybe you can
just use a different variable name.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Script-based code sample library (HTA) VB Script
cannot excute command to open message Vista mail
Is there a shorter code to perform this ps1 script ? PowerShell
MSBuild script for Getlatest cource code .NET General
Help looping a script PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46