找回密码
 加入
搜索
查看: 3119|回复: 6

[AU3基础] 【已解决】IniWrite 写文件的问题

[复制链接]
发表于 2012-9-7 10:14:07 | 显示全部楼层 |阅读模式
本帖最后由 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[1][7]
        $GateWay = $ni[1][2]
        
        $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
谢谢大家!
发表于 2012-9-7 14:39:55 | 显示全部楼层
$wd_r1 = $wd_r2 - (254 - $wd_r1) + 1
检查这一行
发表于 2012-9-7 14:41:52 | 显示全部楼层
line 20:你得读取输入框的数据吧
$Data = GuiCtrlRead($Input1)
$ini_file = @ScriptDir & "\" & $Data & "MAC.ini"
 楼主| 发表于 2012-9-8 05:41:23 | 显示全部楼层
回复 3# zcx880517


    谢谢,按你的方法改后,文件名OK。
 楼主| 发表于 2012-9-8 05:42:46 | 显示全部楼层
回复 2# lpxx


    也谢谢你,加了一个判断,使代码更通用。
 楼主| 发表于 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[1][7]
        $GateWay = $ni[1][2]

        $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
 楼主| 发表于 2012-9-8 06:02:10 | 显示全部楼层

RE: IniWrite 写文件的问题

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

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


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

参考其他人的帖子,终于明白了,怎么弄成【已解决】。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

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

本版积分规则

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

GMT+8, 2024-9-20 15:16 , Processed in 0.081580 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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