找回密码
 加入
搜索
查看: 61610|回复: 170

[原创] 用au3编写网管维护工具(图文教程)

[复制链接]
发表于 2009-2-6 17:49:01 | 显示全部楼层 |阅读模式
声明:这篇文章没有什么技术含量,就是写给新手看的,由于上次论坛数据损坏,电脑上也没有备份,以为丢失了!今天无意间在“云南网吧”网站上找到,特此转接回来!在此感谢云南网吧网站保留了此文章!
=============================================================================================
本教程是用3.2.10来制作的!安装好au3后,在au3目录下运行  AU3TOOL.exe
首先要先设计个维护面板 看图说明














设计完以后 把窗口生成器生成的代码 复制到SCITE编辑器里  红色部分就是需要我们写上去的代码
在SCITE里新建一个脚本 然后复制进去
#include <GUIConstants.au3>
#include <Process.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("维护工具", 251, 81, 297, 252)
$Button1 = GUICtrlCreateButton("控制面版", 20, 8, 75, 25, 0)
$Button2 = GUICtrlCreateButton("显示属性", 20, 48, 75, 25, 0)
$Button3 = GUICtrlCreateButton("系统属性", 132, 8, 75, 25, 0)
$Button4 = GUICtrlCreateButton("进程管理", 132, 48, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        RunWait("c:\windows\system32\control.exe"); 打开控制面板
                        
                Case $Button2
                        _rundos("C:\windows\system32\desk.cpl");打开显示属性
                        
                Case $Button3
                        _RunDOS("c:\windows\system32\sysdm.cpl");打开系统属性
                        
                Case $Button4
                        RunWait("c:\windows\system32\taskmgr.exe");打开任务管理器
        
   EndSwitch
WEnd








简单吧,第一个教程就这样完成了!

[ 本帖最后由 hynq2000 于 2009-2-6 18:19 编辑 ]

本帖子中包含更多资源

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

×
 楼主| 发表于 2009-2-6 17:49:22 | 显示全部楼层
给新手的反思 为什么调用exe文件 用runwait      调用cpl文件用 _rundos
如果用别的方法可不可以?
我也是新手 希望能和大家一起学习
请大家把帖子顶起来 造福更多的au3新手

[ 本帖最后由 hynq2000 于 2009-2-6 18:04 编辑 ]
 楼主| 发表于 2009-2-6 17:49:45 | 显示全部楼层
网管维护工具 扩展版这个作品是上一个的扩展版 看看增加了两个小功能
成品图


步骤一

步骤2

步骤3



红色部分是需要添加上的
==========================================================================
#include <GUIConstants.au3>
#include <Process.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("维护工具测试1", 315, 204, 278, 206)
$Button1 = GUICtrlCreateButton("系统属性", 8, 8, 75, 25, 0)
$Button2 = GUICtrlCreateButton("显示属性", 8, 56, 75, 25, 0)
$Button3 = GUICtrlCreateButton("进程管理", 8, 104, 75, 25, 0)
$Button4 = GUICtrlCreateButton("控制面板", 112, 8, 75, 25, 0)
$Button5 = GUICtrlCreateButton("命令行", 112, 56, 75, 25, 0)
$Button6 = GUICtrlCreateButton("注册表", 112, 104, 75, 25, 0)
$Button7 = GUICtrlCreateButton("Msconfig", 216, 56, 75, 25, 0)
$Button8 = GUICtrlCreateButton("音量控制", 216, 104, 75, 25, 0)
$Button9 = GUICtrlCreateButton("策略组", 216, 8, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 8, 148, 121, 25)
$Button10 = GUICtrlCreateButton("运行", 144, 148, 43, 25, 0)
$Button11 = GUICtrlCreateButton("时间日期", 216, 144, 75, 25, 0)
GUICtrlCreateLabel("", 184, 176, 4, 4)
$Label1 = GUICtrlCreateLabel("蝶-友川医夫2007/11", 176, 186, 132, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
       Case $Button1
                        _RunDOS(@SystemDir &"\sysdm.cpl");打开系统属性
                Case $Button2
                        _RunDOS(@SystemDir &"\desk.cpl");打开显示属性
                Case $Button3
                        Run(@SystemDir &"\taskmgr.exe");打开任务管理器        
                Case $Button4
                        Run(@SystemDir &"\control.exe");打开控制面板        
                Case $Button5
                        Run(@SystemDir &"\cmd.exe");打开命令行
                Case $Button6
                        Run(@WindowsDir &"\regedit.exe");打开注册表
                Case $Button7
                        Run("C:\WINDOWS\pchealth\helpctr\binaries\Msconfig.exe");打开msconfig
                Case $Button8
                        Run(@SystemDir &"\Sndvol32.exe");打开音量控制程序
                Case $Button9
                        ShellExecute(@SystemDir &"\gpedit.msc");打开策略组  另一种写法Run(@ComSpec&' /c gpedit.msc',@SystemDir,@SW_HIDE)
                Case $Button10
                        Run(@ComSpec &" /c "&GUICtrlRead($input1));这里是这个作品的关键 读取文本框里的内容然后运行
                Case $Button11
                        _RunDOS(@SystemDir &"\timedate.cpl");打开时间日期
                Case $Label1
        
  EndSwitch
WEnd
=========================================================================
说明:
这个作品比上个来讲 优化了几处代码 增加了一个读取文本框内容然后运行的机制
运用了au3的库文件 @systemdir==windows\system32  @windowsdir==windows 我的理解库文件就好比是一个快捷方式,用的时候方便一些 不用打那么长的字母
但是我在使用中发现有时候库文件的定位不是那么准确 代码正常的情况下会有时管用有时不管用  这一点请大家注意
还有我的这个代码的按键号码 可能和你生成的按键号码不一致 用的时候改正一下就好了

[ 本帖最后由 hynq2000 于 2009-2-6 20:29 编辑 ]

本帖子中包含更多资源

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

×
 楼主| 发表于 2009-2-6 17:49:52 | 显示全部楼层
4楼备用,方便编辑
 楼主| 发表于 2009-2-6 17:50:01 | 显示全部楼层
5楼备用,方便编辑
 楼主| 发表于 2009-2-6 17:50:09 | 显示全部楼层
6楼备用,方便编辑
发表于 2009-2-6 20:20:03 | 显示全部楼层
#NoTrayIcon        ;禁止系统通知区域(系统托盘)出现本程序图标
#cs
ACN论坛hynq2000的网管工具箱教程为样板,略作修改
修改原因:
1,建议尽可能使用事件模式,事件模式下,绝大部分操作后可以立即执行脚本中的下一步,而不会等待当前操作完成。
2,调用控制面板文件也不是必需用到RUNDOS,可以向控制面板主程序请教执行相应控制面板文件。
3,既然是网管工具箱,自然不可以随便给别人用,所以当加个密码控制,KiwiCsj个人提供简单加密码方案。
3,其它:hynq2000朋友说了是简单教程,所以此为思路扩展,其代码均可根据思路从汉化版帮助中查询:
    a,相关功能可以尝试使用右键菜单集成之,不必每样具体操作都做一个按钮在界面上
        b,...有事忙了,就这样吧,思路是人想出来的,只要你愿意,Au3也可以帮你把很多新鲜的花样玩出来。
#ce
Opt("GUIOnEventMode", 1)        ;声明使用事件模式
#include <GUIConstants.au3> 
;~ #include <Process.au3>        ;没使用_RunDos所以这个可以不用

_KiwiCsjOPSSWD()        ;密码检验过程

#Region ### START Koda GUI section ### Form= 
$Form1 = GUICreate("维护工具测试1B", 315, 204, 278, 206) 
$Button1 = GUICtrlCreateButton("系统属性", 8, 8, 75, 25, 0) 
$Button2 = GUICtrlCreateButton("显示属性", 8, 56, 75, 25, 0) 
$Button3 = GUICtrlCreateButton("进程管理", 8, 104, 75, 25, 0) 
$Button4 = GUICtrlCreateButton("控制面板", 112, 8, 75, 25, 0) 
$Button5 = GUICtrlCreateButton("命令行", 112, 56, 75, 25, 0) 
$Button6 = GUICtrlCreateButton("注册表", 112, 104, 75, 25, 0) 
$Button7 = GUICtrlCreateButton("Msconfig", 216, 56, 75, 25, 0) 
$Button8 = GUICtrlCreateButton("音量控制", 216, 104, 75, 25, 0) 
$Button9 = GUICtrlCreateButton("策略组", 216, 8, 75, 25, 0) 
$Input1 = GUICtrlCreateInput("", 8, 148, 121, 25) 
$Button10 = GUICtrlCreateButton("运行", 144, 148, 43, 25, 0) 
$Button11 = GUICtrlCreateButton("时间日期", 216, 144, 75, 25, 0) 
GUICtrlCreateLabel("", 184, 176, 4, 4) 
$Label1 = GUICtrlCreateLabel("蝶-友川医夫2007/11", 176, 186, 132, 17) 
GUISetState(@SW_SHOW) 
#EndRegion ### END Koda GUI section ### 
;######### 声明事件关联 始 ###########
GUISetOnEvent($GUI_EVENT_CLOSE, "kc_exit")        ;声明关闭操作要调用的函数
GUICtrlSetOnEvent($Button1, "KcTask")                ;声明每个按钮操作要调用的函数
GUICtrlSetOnEvent($Button2, "KcTask")
GUICtrlSetOnEvent($Button3, "KcTask")
GUICtrlSetOnEvent($Button4, "KcTask")
GUICtrlSetOnEvent($Button5, "KcTask")
GUICtrlSetOnEvent($Button6, "KcTask")
GUICtrlSetOnEvent($Button7, "KcTask")
GUICtrlSetOnEvent($Button8, "KcTask")
GUICtrlSetOnEvent($Button9, "KcTask")
GUICtrlSetOnEvent($Button10, "KcTask")
GUICtrlSetOnEvent($Button11, "KcTask")
GUICtrlSetOnEvent($Label1, "KcTask")                ;文字也可以声明点击时可调用的函数
;######### 声明事件关联 毕,进入主循环 ###########
While 1 
        Sleep(1)
WEnd
;######### 自定义一些前面要用到的函数 ###########

Func KcTask()        ;主体界面上的按钮类操作 ,以事件模式工作
        Switch @GUI_CtrlId
                Case $Button1 
                                Run(@SystemDir&"\control.exe sysdm.cpl")        ;打开系统属性 
                Case $Button2 
                                Run(@SystemDir&"\control.exe desk.cpl")                ;打开显示属性 
                Case $Button3 
                                Run(@SystemDir &"\taskmgr.exe")                                ;打开任务管理器        
                Case $Button4 
                                Run(@SystemDir &"\control.exe")                                ;打开控制面板        
                Case $Button5 
                                Run(@SystemDir &"\cmd.exe")                                        ;打开命令行 
                Case $Button6 
                                Run(@WindowsDir &"\regedit.exe")                        ;打开注册表 
                Case $Button7 
                                Run("C:\WINDOWS\pchealth\helpctr\binaries\Msconfig.exe");打开msconfig 
                Case $Button8 
                                Run(@SystemDir &"\Sndvol32.exe")                        ;打开音量控制程序 
                Case $Button9 
                                ShellExecute(@SystemDir &"\gpedit.msc")                ;打开策略组  另一种写法Run(@ComSpec&' /c gpedit.msc',@SystemDir,@SW_HIDE) 
                Case $Button10 
                                Run(@ComSpec &" /c "&GUICtrlRead($input1))        ;这里是这个作品的关键 读取文本框里的内容然后运行 
                Case $Button11 
                                Run(@SystemDir&"\control.exe timedate.cpl")        ;打开时间日期 
                Case $Label1         
                                Run(@ProgramFilesDir&"\Internet Explorer\IEXPLORE.EXE http://www.autoitx.com/space.php?uid=418&sid=NEZ90P")
        EndSwitch
EndFunc ;==> KcTask

Func _KiwiCsjOPSSWD()        ;密码检验过程
        $kcps = "hynq2000"        ;定义密码,如果有必要,你还可以再用别的办法重复加密一下
        $input=InputBox("愿与你望月共醉", "请回答口令:", "", ".",220,120,-1,-1,16)        ;研究一下InputBox的函数,它的参数很值得一用。
        if @error=0 Then
                If $kcps <> $input Then
                        MsgBox (262144+32,"真遗憾!!!","想不起来了?",9)
                        kc_exit()                ;调用退出
                Else                                ;密码检查通过
                        $input=""
                EndIf
        ElseIf @error=1 Then
                kc_exit()
        ElseIf @error=2 Then 
                MsgBox (262144+32,"真遗憾!!!","回答个口令有这么慢么?",9)
                kc_exit()
        ElseIf @error=3 Then 
                MsgBox (262144+16,"意外错误!!!","口令输入框显示失败!请重试!",9)
                kc_exit()
        Else
                kc_exit()
        EndIf
EndFunc ;==> _KiwiCsjOPSSWD

Func kc_exit()        ;退出时的动作定义
        Exit
EndFunc ;==> kc_exit


[ 本帖最后由 KiwiCsj 于 2009-2-6 20:25 编辑 ]
 楼主| 发表于 2009-2-6 20:37:58 | 显示全部楼层
不错,很喜欢 让我也明白了什么是事件模式
还有这个密码验证 需要时间限制这个方法够新颖
发表于 2009-2-6 22:50:11 | 显示全部楼层
好贴 我以前若是看到这张贴就会节省不少时间了
发表于 2009-2-7 20:46:40 | 显示全部楼层
谢谢提供 学习了.
 楼主| 发表于 2009-2-12 00:57:22 | 显示全部楼层
顶上去···顶上去
发表于 2009-2-13 14:40:05 | 显示全部楼层
。。。学习一下。
发表于 2009-2-19 01:43:10 | 显示全部楼层
这篇让我学了很多
发表于 2009-2-19 01:44:23 | 显示全部楼层
这篇让我学了很多
发表于 2009-2-19 05:01:35 | 显示全部楼层
为什么我做的时候``运行cpl的文件的时候会没有用呢。什么都没有出.也没提示会什么..如果我改成-rundos的话`运行的时候就会出错呢 - 等高手来解答`
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-28 21:19 , Processed in 0.080145 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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