hgzzy 发表于 2012-9-7 10:14:07

【已解决】IniWrite 写文件的问题

本帖最后由 hgzzy 于 2012-9-8 06:06 编辑

请大家帮我看下,为什么文件名不能按输入框里的名字生成。$Form1 = GUICreate("Hgzzy-Mac", 351, 275, 192, 124)
GUISetFont(10, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("输入文件名", 40, 160, 84, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
$Input1 = GUICtrlCreateInput("65010", 216, 160, 81, 24)
GUICtrlSetColor(-1, 0x008080)
$Group1 = GUICtrlCreateGroup("使用说明", 24, 16, 297, 121)
$Label2 = GUICtrlCreateLabel("本程序为获取本网段 IP 和 MAC 而设计", 32, 40, 278, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
$Label3 = GUICtrlCreateLabel("By Hgzzy 2012.8", 168, 88, 123, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("确       定", 32, 216, 105, 25)
$Button2 = GUICtrlCreateButton("退       出", 200, 216, 105, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$ini_file = @ScriptDir & "\" & $Input1 & "MAC.ini"

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GetMac()
                Case $Button2
                        Exit

        EndSwitch
WEnd


Func GetMac()
       
        $ni = _NetworkAdapterInfo()
        $SubMask = $ni
        $GateWay = $ni
       
        $wd_tou1 = StringInStr($SubMask, ".", 0, 3)
        $wd_tou2 = StringInStr($GateWay, ".", 0, 3)
       
        $wd = StringLeft(@IPAddress1, $wd_tou2)
        $wd_r1 = StringRight($SubMask, StringLen($SubMask) - $wd_tou1)       
        $wd_r2 = StringRight($GateWay, StringLen($GateWay) - $wd_tou2)
        $wd_r1 = $wd_r2 - (254 - $wd_r1) + 1
       
        For $i = $wd_r1 To $wd_r2
                $info = _API_Get_NetworkAdapterMAC($wd & $i)
                TrayTip("正在获取如下IP的MAC", $wd & $i, 5, 1)

                If $info <> "00:00:00:00:00:00" Then
                        IniWrite($ini_file, "mac", $info, $wd & $i)
                EndIf
        Next
        MsgBox(0, 'hgzzy提示', "完成本网段的信息收集", 3)
        Exit
EndFunc   ;==>GetMac
谢谢大家!

lpxx 发表于 2012-9-7 14:39:55

$wd_r1 = $wd_r2 - (254 - $wd_r1) + 1
检查这一行

zcx880517 发表于 2012-9-7 14:41:52

line 20:你得读取输入框的数据吧
$Data = GuiCtrlRead($Input1)
$ini_file = @ScriptDir & "\" & $Data & "MAC.ini"

hgzzy 发表于 2012-9-8 05:41:23

回复 3# zcx880517


    谢谢,按你的方法改后,文件名OK。

hgzzy 发表于 2012-9-8 05:42:46

回复 2# lpxx


    也谢谢你,加了一个判断,使代码更通用。

hgzzy 发表于 2012-9-8 05:44:18

完整的代码:#include <acn_net.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Hgzzy-Mac", 351, 275, 192, 124)
GUISetFont(10, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("输入文件名", 40, 160, 84, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
$Input1 = GUICtrlCreateInput("65010", 216, 160, 81, 24)
GUICtrlSetColor(-1, 0x008080)
$Group1 = GUICtrlCreateGroup("使用说明", 24, 16, 297, 121)
$Label2 = GUICtrlCreateLabel("本程序为获取本网段 IP 和 MAC 而设计", 32, 40, 278, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
$Label3 = GUICtrlCreateLabel("By Hgzzy 2012.8", 168, 88, 123, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("确       定", 32, 216, 105, 25)
$Button2 = GUICtrlCreateButton("退       出", 200, 216, 105, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$Data = GUICtrlRead($Input1)
$ini_file = @ScriptDir & "\" & $Data & "MAC.ini"

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GetMac()
                Case $Button2
                        Exit

        EndSwitch
WEnd


Func GetMac()

        $ni = _NetworkAdapterInfo()
        $SubMask = $ni
        $GateWay = $ni

        $wd_tou1 = StringInStr($SubMask, ".", 0, 3)
        $wd_tou2 = StringInStr($GateWay, ".", 0, 3)

        $wd = StringLeft(@IPAddress1, $wd_tou2)
        $wd_r1 = StringRight($SubMask, StringLen($SubMask) - $wd_tou1)
        $wd_r2 = StringRight($GateWay, StringLen($GateWay) - $wd_tou2)
        $wd_r1 = $wd_r2 - (254 - $wd_r1) + 1
       
        If $wd_r1 < 0 Then
                $wd_r1 = 1
                $wd_r2 = 254
        EndIf

        For $i = $wd_r1 To $wd_r2
                $info = _API_Get_NetworkAdapterMAC($wd & $i)
                TrayTip("正在获取如下IP的MAC", $wd & $i, 5, 1)

                If $info <> "00:00:00:00:00:00" Then
                        IniWrite($ini_file, "mac", $info, $wd & $i)
                EndIf
        Next
        MsgBox(0, 'hgzzy提示', "完成本网段的信息收集", 3)
        Exit
EndFunc   ;==>GetMac

hgzzy 发表于 2012-9-8 06:02:10

RE: IniWrite 写文件的问题

本帖最后由 hgzzy 于 2012-9-8 06:08 编辑

好像在主题分类中没看见“已解决”,麻烦斑竹帮忙。谢谢!


想贴图,可惜多次失败。(呵呵~~自己出来了。)

参考其他人的帖子,终于明白了,怎么弄成【已解决】。
页: [1]
查看完整版本: 【已解决】IniWrite 写文件的问题