Could anybody help with me a script that is able to open a text file
on a remote computer, search it for a specified string, and then
return to me that string AND the line below it (or the next 30
characters).

I'm hoping to query a number of machine's drwtsn32.log files to find
similer errors.

The string I want to search for is "App: C:\Program Files\Internet
Explorer\iexplore.exe." and the line below it would be something like
"When: 10/05/2006 @ 11:01:24.511."

So basically I'm trying to find out when these errors are occurring.

RE: Script to find a string in a text file on a remote computer by RemS

RemS
Tue Jun 19 08:38:15 CDT 2007

"airwot4" wrote:
> Could anybody help with me a script that is able to open a text file
> on a remote computer, search it for a specified string, and then
> return to me that string AND the line below it (or the next 30
> characters).
>
> I'm hoping to query a number of machine's drwtsn32.log files to find
> similer errors.
>
> The string I want to search for is "App: C:\Program Files\Internet
> Explorer\iexplore.exe." and the line below it would be something like
> "When: 10/05/2006 @ 11:01:24.511."
>
> So basically I'm trying to find out when these errors are occurring.
>

Here is a start:


strComputer = "targetcomputername"

Set objShell = Wscript.CreateObject("Wscript.shell")
strDrwtsnLog = "drwtsn32.log"
strDrwtsnpath = objShell.ExpandEnvironmentStrings _
("%AllUsersProfile%\Application Data\Microsoft\Dr Watson")
strDrwtsnpath = """\\"+strComputer+"\"+Replace(strDrwtsnpath, _
":\","$\")+"\"+strDrwtsnLog+""""

Set execObj= objShell.Exec("cmd /c type "+strDrwtsnpath)

Do While Not execObj.StdOut.AtEndOfStream
strVar = execObj.StdOut.ReadLine
If incNextLine = "YES" then
strString2 = strVar
incNextLine = vbNullString
ElseIf Instr(strVar,"App: C:\Program Files\Internet Explorer" & _
"\iexplore.exe (pid=") then
strString1 = strVar
incNextLine = "YES"
Else incNextLine = vbNullString
End If
Loop

msgBox(strComputer+vbNewLine+strString1+vbNewLine+strString2)



\RemS




Re: Script to find a string in a text file on a remote computer by S

S
Tue Jun 19 11:40:40 CDT 2007

you should get intt the habit of using "&" to concat in vbscript as opposed
to "+"


"\RemS" <RemS@discussions.microsoft.com> wrote in message
news:5C191189-1A32-4954-8D6C-C25C2413FC7B@microsoft.com...
> "airwot4" wrote:
>> Could anybody help with me a script that is able to open a text file
>> on a remote computer, search it for a specified string, and then
>> return to me that string AND the line below it (or the next 30
>> characters).
>>
>> I'm hoping to query a number of machine's drwtsn32.log files to find
>> similer errors.
>>
>> The string I want to search for is "App: C:\Program Files\Internet
>> Explorer\iexplore.exe." and the line below it would be something like
>> "When: 10/05/2006 @ 11:01:24.511."
>>
>> So basically I'm trying to find out when these errors are occurring.
>>
>
> Here is a start:
>
>
> strComputer = "targetcomputername"
>
> Set objShell = Wscript.CreateObject("Wscript.shell")
> strDrwtsnLog = "drwtsn32.log"
> strDrwtsnpath = objShell.ExpandEnvironmentStrings _
> ("%AllUsersProfile%\Application Data\Microsoft\Dr Watson")
> strDrwtsnpath = """\\"+strComputer+"\"+Replace(strDrwtsnpath, _
> ":\","$\")+"\"+strDrwtsnLog+""""
>
> Set execObj= objShell.Exec("cmd /c type "+strDrwtsnpath)
>
> Do While Not execObj.StdOut.AtEndOfStream
> strVar = execObj.StdOut.ReadLine
> If incNextLine = "YES" then
> strString2 = strVar
> incNextLine = vbNullString
> ElseIf Instr(strVar,"App: C:\Program Files\Internet Explorer" & _
> "\iexplore.exe (pid=") then
> strString1 = strVar
> incNextLine = "YES"
> Else incNextLine = vbNullString
> End If
> Loop
>
> msgBox(strComputer+vbNewLine+strString1+vbNewLine+strString2)
>
>
>
> \RemS
>
>
>


Re: Script to find a string in a text file on a remote computer by RemS

RemS
Wed Jun 20 05:31:02 CDT 2007

"S Moran" wrote:
> you should get intt the habit of using "&" to concat in vbscript as opposed
> to "+"

Luckyly notepad has a Find&Replace function then.

My habit btw IS using & and not +
:)

airwot4 ,
Note that the script is expanding the %AllUsersProfile% variable from *your*
computer - Not from the environment on the remote computer!
It uses that same path to browse on the target computer. So the script
assumes the "All Users" folder is on the same path on both computers.
If not, then manually provide the correct path for the target computer
(using the administrative share to access the target computer).


grtz,


> "\RemS" <RemS@discussions.microsoft.com> wrote in message
> news:5C191189-1A32-4954-8D6C-C25C2413FC7B@microsoft.com...
> > "airwot4" wrote:
> >> Could anybody help with me a script that is able to open a text file
> >> on a remote computer, search it for a specified string, and then
> >> return to me that string AND the line below it (or the next 30
> >> characters).
> >>
> >> I'm hoping to query a number of machine's drwtsn32.log files to find
> >> similer errors.
> >>
> >> The string I want to search for is "App: C:\Program Files\Internet
> >> Explorer\iexplore.exe." and the line below it would be something like
> >> "When: 10/05/2006 @ 11:01:24.511."
> >>
> >> So basically I'm trying to find out when these errors are occurring.
> >>
> >
> > Here is a start:
> >
> >
> > strComputer = "targetcomputername"
> >
> > Set objShell = Wscript.CreateObject("Wscript.shell")
> > strDrwtsnLog = "drwtsn32.log"
> > strDrwtsnpath = objShell.ExpandEnvironmentStrings _
> > ("%AllUsersProfile%\Application Data\Microsoft\Dr Watson")
> > strDrwtsnpath = """\\"+strComputer+"\"+Replace(strDrwtsnpath, _
> > ":\","$\")+"\"+strDrwtsnLog+""""
> >
> > Set execObj= objShell.Exec("cmd /c type "+strDrwtsnpath)
> >
> > Do While Not execObj.StdOut.AtEndOfStream
> > strVar = execObj.StdOut.ReadLine
> > If incNextLine = "YES" then
> > strString2 = strVar
> > incNextLine = vbNullString
> > ElseIf Instr(strVar,"App: C:\Program Files\Internet Explorer" & _
> > "\iexplore.exe (pid=") then
> > strString1 = strVar
> > incNextLine = "YES"
> > Else incNextLine = vbNullString
> > End If
> > Loop
> >
> > msgBox(strComputer+vbNewLine+strString1+vbNewLine+strString2)
> >
> >
> >
> > \RemS


Re: Script to find a string in a text file on a remote computer by airwot4

airwot4
Wed Jun 27 03:52:41 CDT 2007

That works great, thank you.

One problem is that there are often numerous strings of this type in
the drwtsn32.log file. I need the first to be returned (the earliest),
at the moment the last is returned.


Re: Script to find a string in a text file on a remote computer by RemS

RemS
Tue Jul 03 12:40:01 CDT 2007

"airwot4" wrote:

> That works great, thank you.
>
> One problem is that there are often numerous strings of this type in
> the drwtsn32.log file. I need the first to be returned (the earliest),
> at the moment the last is returned.
>


That is possible.
In the previous script, the DO WHILE loop goes through the complete file,
overwriting the earlier hits.

The script below stops the DO WHILE loop directly after the first hit:


strComputer = "targetcomputername"

Set objShell = Wscript.CreateObject("Wscript.shell")
strDrwtsnLog = "drwtsn32.log"
strDrwtsnpath = objShell.ExpandEnvironmentStrings _
("%AllUsersProfile%\Application Data\Microsoft\Dr Watson")
strDrwtsnpath = """\\" & strComputer & "\" & Replace(strDrwtsnpath, _
":\","$\") & "\" & strDrwtsnLog & """"

Set execObj= objShell.Exec("cmd /c type " & strDrwtsnpath)

Do While Not execObj.StdOut.AtEndOfStream
strVar = execObj.StdOut.ReadLine
If incNextLine = "YES" then
strString2 = strVar
exit Do
ElseIf Instr(strVar,"App: C:\Program Files\Internet Explorer" & _
"\iexplore.exe (pid=") then
strString1 = strVar
incNextLine = "YES"
Else incNextLine = vbNullString
End If
Loop

msgBox(strComputer & vbNewLine & strString1 & vbNewLine & strString2)


---------------
\RemS