关于查询文件中是否含有指定的文字然后弹窗(已解决)
本帖最后由 shenrenba 于 2010-8-20 15:55 编辑比如下面的代码 我想在写入之前先查询HOSTS文件中是否已经写入 请问如何解决#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("注册表", 300, 200)
$Group1 = GUICtrlCreateGroup("Group1", 0, 0, 300, 300)
$Button1 = GUICtrlCreateButton("添加", 50,80,60,40)
$Button2 = GUICtrlCreateButton("删除", 200, 80, 60, 40)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
FileWrite(@SystemDir&"\drivers\etc\hosts","------ 屏蔽千千静听开始 ------"&@LF&"0.0.0.0 ttmsg.qianqian.com"&@LF&"------ 屏蔽千千静听结束 ------")
MsgBox(0,"","操作已完成")
EndSwitch
WEnd
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("注册表", 300, 200)
$Group1 = GUICtrlCreateGroup("Group1", 0, 0, 300, 300)
$Button1 = GUICtrlCreateButton("添加", 50,80,60,40)
$Button2 = GUICtrlCreateButton("删除", 200, 80, 60, 40)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$file = @SystemDir&"\drivers\etc\hosts"
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$t = FileRead($file)
If StringInStr($t,"ttmsg.qianqian.com") <> 0 Then
MsgBox(0,"提示","千千静听已屏蔽")
Else
FileWrite($file,@LF&"------ 屏蔽千千静听开始 ------"&@LF&"0.0.0.0 ttmsg.qianqian.com"&@LF&"------ 屏蔽千千静听结束 ------")
MsgBox(0,"","操作已完成")
EndIf
EndSwitch
WEndStringInStr
--------------------------------------------------------------------------------
检查某个字符串是否含有指定的子字符串.
StringInStr ( "字符串", "子字符串" [, 区分大小写 [, 出现次序 [, 开始 [, 数量]]]] )
具体可看
http://www.autoitx.com/Doc/html/functions/stringinstr.htm
页:
[1]