Jump to content

not finding string with stringinstr what am I doing wrong


Recommended Posts

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)

Link to comment
Share on other sites

$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.

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...