找回密码
 加入
搜索
查看: 2445|回复: 1

[AU3基础] 关于查询文件中是否含有指定的文字然后弹窗(已解决)

[复制链接]
发表于 2010-8-20 15:34:03 | 显示全部楼层 |阅读模式
本帖最后由 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

评分

参与人数 1金钱 +10 收起 理由
pusofalse + 10 感谢主动给标题加“已解决”字样。

查看全部评分

发表于 2010-8-20 15:45:53 | 显示全部楼层
#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
WEnd
StringInStr
--------------------------------------------------------------------------------

检查某个字符串是否含有指定的子字符串.


StringInStr ( "字符串", "子字符串" [, 区分大小写 [, 出现次序 [, 开始 [, 数量]]]] )

具体可看
http://www.autoitx.com/Doc/html/functions/stringinstr.htm

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-3 10:41 , Processed in 0.078300 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表