Sign in to follow this  
Followers 0
AntiVirusGuy

not finding string with stringinstr what am I doing wrong

4 posts in this topic

why cant I search this file for a given string? You can see where I have a line remmed out to test that the file read is working and the string is there. What am I doing wrong? I thought this would be an easy way to check for services using serviwin Help!

$file = FileOpen("C:\services.html", 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to detect Service")

Exit

EndIf

While 1

$line = FileRead($file,100000)

If @error = -1 Then ExitLoop

;MsgBox(0, "Line read:", $line)

Wend

$result = StringInStr($line,"Windows")

MsgBox(0, @error, $result)

FileClose($file)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$file = FileOpen("C:\services.html", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to detect Service")
    Exit
EndIf

$file_lines = ""
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $file_lines = $file_lines & $line & @CRLF
;MsgBox(0, "Line read:", $line)
WEnd
FileClose($file)


$result = StringInStr($file_lines, "Windows")
MsgBox(0, @error, $result)

or you could do

$line = FileRead($file,FileGetSize("C:\services.html"))

no need for loop then.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Why do you need that

$file_lines = ""

what does it do???? (other than make it work, thank you) B)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0