找回密码
 加入
搜索
查看: 3705|回复: 4

[系统综合] [已解决] 如何判断禁止重复写入相同的数据。谢谢。

[复制链接]
发表于 2011-12-15 11:24:02 | 显示全部楼层 |阅读模式
本帖最后由 pingfan5888 于 2011-12-15 18:51 编辑

; 如何在63行,这判断写入重复数据。INI已存在的IP,不在添加写入新行。,谢谢。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#Region ### START Koda GUI section ### Form=F:\绿色软件\IE7\教程\proxy\form1.kxf
$Form1 = GUICreate("IE代理设置", 209, 139, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 5, 193, 121)
$Label1 = GUICtrlCreateLabel("状态:", 24, 21, 40, 17)
$status = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable")
If $status = 0 Then
        $Label2 = GUICtrlCreateLabel("代理已关闭", 62, 22, 120, 17)
Else
        $Label2 = GUICtrlCreateLabel("代理已启用", 62, 22, 120, 17)
EndIf
$ip1 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer")
If $ip1 = '' Then
        $Combo1 = GUICtrlCreateCombo('112.217.228.212:8080', 24, 45, 161, 21, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
        GUICtrlSetTip($Combo1, "输入格式:IP:Port(如:112.217.228.212.8080)!")
Else
        $Combo1 = GUICtrlCreateCombo('112.217.228.212:8080', 24, 45, 161, 21, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
        GUICtrlSetData($Combo1, $ip1)
        GUICtrlSetTip($Combo1, "输入格式:IP:Port(如:112.217.228.212.8080)!")
EndIf
GUICtrlSetState($Combo1, $GUI_EXPAND)
$Button1 = GUICtrlCreateButton("启用", 24, 85, 65, 25)
$Button2 = GUICtrlCreateButton("禁用", 117, 85, 65, 25)
$Label = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $var
$z = 0
$var = IniReadSection(@ScriptDir & "\proxy.ini", "proxy")
If @error Then
Else
        For $i = 1 To $var[0][0]
                GUICtrlSetData($Combo1, $var[$i][1], 0)
                GUICtrlSetData($Label, $z + 1)
                $z += 1
        Next
EndIf

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUISetState(@SW_HIDE, $Form1)
                        $z = GUICtrlRead($Label)
                        $doit = GUICtrlRead($Combo1)
                        $ip = StringRegExpReplace($doit, ":.*", "")
                        $PORT = StringRegExpReplace($doit, ".*:", "")

                        If StringInStr($doit, ":") And StringIsDigit(StringReplace($ip, ".", "")) And StringReplace($ip, ".", "") > 0 And $PORT > 0 And StringInStr($ip, ".", 0, 3) And StringIsDigit($PORT) And Not StringInStr($ip, ".", 0, 4) Then
                                RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $doit)
                                RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 1)
                                $z += 1
                                ;如何在这判断INI中已存在IP,则不在新行重复写入
                                
                                IniWrite(@ScriptDir & "\proxy.ini", 'proxy', $z, $doit)
                                GUICtrlSetData($Label, $z + 1)

                                MsgBox(64, "IE代理设置", "代理启用", 2)
                                DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
                                Exit

                        Else
                                GUISetState(@SW_HIDE, $Form1)
                                MsgBox(48, "IE代理设置", "输入错误,请重新输入!" & @CRLF & "输入格式:IP:Port(如:112.217.228.212.8080)!")
                                GUISetState(@SW_SHOW, $Form1)
                        EndIf
                Case $Button2
                        GUISetState(@SW_HIDE, $Form1)
                        RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 0)
                        MsgBox(64, "IE代理设置", "代理关闭", 2)
                        DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
                        Exit

        EndSwitch
WEnd
发表于 2011-12-15 11:50:05 | 显示全部楼层
既然有比较, 至少存在两个数据,
你上面的代码至少在比较作判断前把另一数据给读出来吧?
缺少了读取实时的注册表的相关值.
 楼主| 发表于 2011-12-15 12:41:32 | 显示全部楼层
我来说错了,是在63行写入INI时判断禁止重复写入的比较。
发表于 2011-12-15 17:04:08 | 显示全部楼层
lz把代码整理好也许解答的人会多些
 楼主| 发表于 2011-12-15 18:51:12 | 显示全部楼层
自己解决了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 23:15 , Processed in 0.087812 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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