绿色风's Blog
专注AutoIT(Au3)
  • 首页
  • 流●年
  • 笔●记
    • 学习随记
    • 源码示例
  • 脚●本
    • UDF(收集)
    • 工作室UDF
    • 工具●教程
    • 教程之GDI
  • 作●品
  • 下●载
  • 情怀ExcelTip
12月72016

Au3定时关机精灵(仿定时强制关机精力1.0)含源码

作者:绿色风   发布:2016-12-7 12:57 Wednesday   分类:源码示例   阅读:7426次   评论:0条  

转载:http://www.autoitx.com/thread-54088-1-1.html 作者:q410225

定时强制关机精力1.0是我收藏中的一款软件,整个程序很小巧,只有200K,实现的功能也很简单就是定时关机重启之类,我中意他的原因是强制二字,不会因为有未结束的程序之类让系统无法重启关机.

为了能更熟悉AU3 gui方面的知识,我第一眼就打算仿制这款软件.
A111.jpg

网络校时使用的是咱们论坛的源代码

自我保护并没有原版强大,原版可以实现进程保护,我这个只能实现简单的密码保护

禁用修改时间后,我使用的方法是把system目录里的timedate.cpl移动到程序目录为timedate.dll,程序退出的时候后复原,这点需要注意,现在想想直接在system改名更好.

程序启动的时候会写入启动项,而点退出的后会自动删除启动项.

重启关机直接调用的AU3函数,没有试验过是否有原版那么强制



#AutoIt3Wrapper_Icon=
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (c) lydown 2016
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_Fileversion=1.2.12
#AutoIt3Wrapper_Res_ProductVersion=1.2.12
#AutoIt3Wrapper_Res_Language=2052
#AutoIt3Wrapper_Res_Field=作者|lydown
#AutoIt3Wrapper_Res_Comment=定时关机精灵V1.0
#AutoIt3Wrapper_Res_Description=定时关机精灵V1.0
#cs ____________________________________
        定时关机精灵,仿定时强制关机小精灵的作品
        已经基本实现了原程序大部分的功能,不过像原程序进程保护,文件保护的功能,只能待
        以后提高后再重新设计了.
        对软件功能进行了一些优化,比如启动后会写如开机自启的注册表文件,但退出后会删除.

#ce _______________脚本开始_________________

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Date.au3>

Opt("TrayMenuMode", 1 + 2)
Opt("TrayIconHide", 0)
Opt("TrayAutoPause", 0)
HotKeySet("^!{Up}", "_HotKey")
#Region ### START Koda GUI section ###
Global $Form1 = GUICreate("定时强制关机精灵1.0", 300, 327, 192, 114)
Global $Group1 = GUICtrlCreateGroup(" 定时关机选项", 8, 8, 281, 97)
Global $Label2 = GUICtrlCreateLabel("系统将在每天", 24, 32, 76, 17)
Global $Combo1 = GUICtrlCreateCombo("", 97, 27, 36, 17, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
Global $Label3 = GUICtrlCreateLabel("时", 137, 32, 16, 17)
Global $Combo2 = GUICtrlCreateCombo("", 153, 27, 36, 17, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
Global $Label4 = GUICtrlCreateLabel("分执行下列操作", 196, 32, 88, 17)
Global $Radio1 = GUICtrlCreateRadio("关机", 24, 80, 49, 17)
Global $Radio2 = GUICtrlCreateRadio("重启", 96, 80, 57, 17)
Global $Radio3 = GUICtrlCreateRadio("注销", 160, 80, 49, 17)
Global $Radio4 = GUICtrlCreateRadio("锁定", 224, 80, 49, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group2 = GUICtrlCreateGroup("定时开机", 8, 112, 281, 49)
Global $Label1 = GUICtrlCreateLabel("部分主板支持定时开机功能,请查阅相关设" & @CRLF & "置教程", 36, 126, 305, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Group3 = GUICtrlCreateGroup("高级选项", 8, 168, 281, 121)
Global $Checkbox1 = GUICtrlCreateCheckbox("启用自我保护,设置密码", 16, 192, 153, 17, $BS_AUTOCHECKBOX)
Local $Input = GUICtrlCreateInput("", 173, 192, 70, 17, $ES_PASSWORD)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Checkbox2 = GUICtrlCreateCheckbox("程序运行时禁止修改系统时间。", 16, 216, 185, 17, $BS_AUTOCHECKBOX)
Global $Checkbox3 = GUICtrlCreateCheckbox("每天8:30分自动与授时服务器校准时间。", 16, 240, 249, 17, $BS_AUTOCHECKBOX)
Global $Checkbox4 = GUICtrlCreateCheckbox("当同时按下ctrl+alt+UP键时,系统瞬间重启。", 16, 264, 257, 17, $BS_AUTOCHECKBOX)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Button1 = GUICtrlCreateButton("确定", 208, 296, 73, 25)
;
Global $ts1 = TrayCreateItem("程序设置")
Global $ts2 = TrayCreateItem("网络校时")
TrayCreateItem("")
Global $ts3 = TrayCreateItem("系统休眠")
Global $ts4 = TrayCreateItem("注销当前用户")
Global $ts5 = TrayCreateItem("系统重启")
Global $ts6 = TrayCreateItem("关闭系统")
TrayCreateItem("")
Global $ts0 = TrayCreateItem("退出程序")

#EndRegion ### END Koda GUI section ###
Global Const $set1 = "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|00"
Global $set2 = _
                "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60"

RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "定时强制关机精灵", "REG_SZ", @ScriptFullPath)

Global $hour, $minute, $pwd
Global $type, $nettime, $hide, $lctime, $hotkey
_main()
Exit

Func _main()
        _inird()
        GUICtrlSetData($Combo1, $set1, $hour)
        GUICtrlSetData($Combo2, $set2, $minute)
        While 1
                 If Number($hour) = @HOUR And Number($minute) = @MIN Then ExitLoop
                If @HOUR = 8 And @MIN = 30 And $nettime = 1 Then
                        _gettime()
                EndIf
                Local $_ts = TrayGetMsg()
                Switch $_ts
                        Case $ts0

                                _pdcheck("E")
                        Case $ts1
                                _pdcheck("F")
                        Case $ts2
                                ; 校正系统时间
                                _gettime()
                        Case $ts3
                                ;休眠
                                _shutdown(5)
                        Case $ts4
                                _shutdown(3)
;~                         Shutdown(0)注销
                        Case $ts5
                                _shutdown(2)
;~                         Shutdown(2 + 4)重启
                        Case $ts6
                                _shutdown(1)
;~                         Shutdown(1 + 4 + 8)关机

                EndSwitch
        WEnd
        _shutdown($type)
EndFunc   ;==>_main
Func _shutdown($type)
        For $step = 3 To 1 Step -1
                TrayTip("警告", $step & "正在执行操作...", 0, 1)
                Sleep(1000)
        Next
        TrayTip("", "", 0)
        Switch $type
                Case 1
;~                         MsgBox(0, "", "关机")
                        Shutdown(1 + 4 + 8)
                Case 2
;~                         MsgBox(0, "", "重启")
                         Shutdown(2 + 4)
                Case 3
;~                         MsgBox(0, "", "注销")
                        Shutdown(0)
                Case 4
;~                         MsgBox(0, "", "锁定")
                        Send("#L")
                Case 5
;~                         MsgBox(0, "", "休眠")
                        Shutdown(64)
        EndSwitch
        Exit
EndFunc   ;==>_shutdown

Func _form()

        GUISetState(@SW_SHOW, $Form1)
        While 1
                Local $idMsg = GUIGetMsg()
                Local $gur1 = GUICtrlRead($Checkbox1)
                Local $gur2 = GUICtrlRead($Checkbox2)
                Local $gur3 = GUICtrlRead($Checkbox3)
                Local $gur4 = GUICtrlRead($Checkbox4)
                Switch $idMsg
                        Case $Button1
                                ExitLoop
                        Case $Radio1
                                $type = "1"
                        Case $Radio2
                                $type = "2"
                        Case $Radio3
                                $type = "3"
                        Case $Radio4
                                $type = "4"
                        Case $Checkbox1
                                If $gur1 = $GUI_CHECKED Then
                                        $hide = 1
                                        GUICtrlSetState($Input, $GUI_ENABLE)
                                Else
                                        $hide = 0
                                        GUICtrlSetState($Input, $GUI_DISABLE)
                                EndIf
                        Case $Checkbox2
                                If $gur2 = $GUI_CHECKED Then
                                        $lctime = 1
                                Else
                                        $lctime = 0
                                EndIf

                        Case $Checkbox3
                                If $gur3 = $GUI_CHECKED Then
                                        $nettime = 1
                                Else
                                        $nettime = 0
                                EndIf

                        Case $Checkbox4
                                If $gur4 = $GUI_CHECKED Then
                                        $hotkey = 1
                                Else
                                        $hotkey = 0
                                EndIf

                        Case $GUI_EVENT_CLOSE
                                GUISetState(@SW_HIDE, $Form1)
                                _main()
                EndSwitch
        WEnd
        GUISetState(@SW_HIDE, $Form1)
        _rfwin($type, $nettime, $hide, $lctime, $hotkey)
        _main()
EndFunc   ;==>_form

Func _gettime()
        Local $time = GetTime()
        Local $ntime, $H, $M, $S
        $ntime = StringRegExp($time, "\d+\:\d+\:\d+", 3)
        If Not IsArray($ntime) Then Exit (MsgBox(0, "", "获取时间失败")) ;检查变量是否为数组类型.
        If $ntime[0] <> _NowTime() Then
                $time = GetTime()
                $ntime = StringRegExp($time, "\d+\:\d+\:\d+", 3)
                $H = StringRegExp($ntime[0], "(\d+)\:", 3)
                $M = StringRegExp($ntime[0], "\:(\d+)\:", 3)
                $S = StringRegExp($ntime[0], "\:\d+\:(\d+)", 3)
                _SetTime($H[0], $M[0], $S[0])
                MsgBox(4096, "提示", "校时成功!")
        EndIf
EndFunc   ;==>_gettime

Func _rfwin($type, $nettime, $hide, $lctime, $hotkey)
        Local $idMsg = GUIGetMsg()
        $hour = GUICtrlRead($Combo1)
        $minute = GUICtrlRead($Combo2)
        $pwd = GUICtrlRead($Input)
        IniWrite(@ScriptDir & "\time.ini", "time", "hour", $hour)
        IniWrite(@ScriptDir & "\time.ini", "time", "minute", $minute)
        IniWrite(@ScriptDir & "\time.ini", "time", "type", $type)
        IniWrite(@ScriptDir & "\time.ini", "config", "nettime", $nettime)
        IniWrite(@ScriptDir & "\time.ini", "config", "hide", $hide)
        IniWrite(@ScriptDir & "\time.ini", "config", "lctime", $lctime)
        IniWrite(@ScriptDir & "\time.ini", "config", "hotkey", $hotkey)
        IniWrite(@ScriptDir & "\time.ini", "config", "pwd", $pwd)
EndFunc   ;==>_rfwin

Func _inird()
        $hour = IniRead(@ScriptDir & "\time.ini", "time", "hour", "")
        $minute = IniRead(@ScriptDir & "\time.ini", "time", "minute", "")
        $type = IniRead(@ScriptDir & "\time.ini", "time", "type", "")
        Switch $type
                Case 1
                        GUICtrlSetState($Radio1, $GUI_CHECKED)
                Case 2
                        GUICtrlSetState($Radio2, $GUI_CHECKED)
                Case 3
                        GUICtrlSetState($Radio3, $GUI_CHECKED)
                Case 4
                        GUICtrlSetState($Radio4, $GUI_CHECKED)
        EndSwitch
        $nettime = IniRead(@ScriptDir & "\time.ini", "config", "nettime", "")
        If $nettime = 1 Then GUICtrlSetState($Checkbox3, $GUI_CHECKED)
        $hide = IniRead(@ScriptDir & "\time.ini", "config", "hide", "")
        If $hide = 1 Then
                GUICtrlSetState($Checkbox1, $GUI_CHECKED)
                GUICtrlSetState($Input, $GUI_ENABLE)
        EndIf
        $lctime = IniRead(@ScriptDir & "\time.ini", "config", "lctime", "")
        If $lctime = 1 Then
                GUICtrlSetState($Checkbox2, $GUI_CHECKED)
                FileMove(@SystemDir & "\timedate.cpl", @ScriptDir & "\timedate.dll", 1)
        Else
                FileMove(@ScriptDir & "\timedate.dll", @SystemDir & "\timedate.cpl")
        EndIf
        $hotkey = IniRead(@ScriptDir & "\time.ini", "config", "hotkey", "")
        If $hotkey = 1 Then GUICtrlSetState($Checkbox4, $GUI_CHECKED)
        $pwd = IniRead(@ScriptDir & "\time.ini", "config", "pwd", "")
        Return
EndFunc   ;==>_inird

Func _pdcheck($call)

        If $pwd <> "" And $hide = 1 Then
                Local $pdchk = GUICreate(" 验证密码", 240, 30)
                Local $idFile = GUICtrlCreateInput("", 10, 5, 150, 20, $ES_PASSWORD)
                GUICtrlSetState(-1, $GUI_DROPACCEPTED)
                Local $idBtn = GUICtrlCreateButton("Ok", 170, 5, 60, 20)
                GUISetState(@SW_SHOW)
                While 1
                        Switch GUIGetMsg()
                                Case $GUI_EVENT_CLOSE

                                        GUISetState(@SW_HIDE)
                                        _main()
                                Case $idBtn
                                        If $pwd == GUICtrlRead($idFile) Then
                                                ExitLoop
                                        Else
                                                MsgBox(4096, "错误", "验证失败")
                                        EndIf
                        EndSwitch
                WEnd
        EndIf
        GUISetState(@SW_HIDE)
;~         GUIDelete($pdchk)
        If $call = "F" Then
                _form()
        ElseIf $call = "E" Then
                FileMove(@ScriptDir & "\timedate.dll", @SystemDir & "\timedate.cpl")
                RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "定时强制关机精灵")
                Exit
        EndIf
EndFunc   ;==>_pdcheck

Func GetTime()
        Local $http = 'http://www.timedate.cn/worldclock/ti.asp'
        Local $sData = InetRead($http, 1) ;使用 HTTP,HTTPS 或 FTP 协议下载文件.返回二进制字符串, @extended 为下载的字节数.
        Local $Source = BinaryToString($sData, 1) ;转换二进制变量为字符串.
        Local $aSR = StringRegExp($Source, 'n\w+\=(\d+)', 3)
        If @error Or UBound($aSR) < 7 Then Exit ;返回数组维度的大小或者 map 结构的键数.
        Local $Array[8] = ['日', '一', '二', '三', '四', '五', '六', '日']
        Local $time = StringFormat('%d年%d月%d日 星期%s %02d:%02d:%02d', $aSR[0], $aSR[1], $aSR[2], $Array[$aSR[3]], $aSR[4], $aSR[5], $aSR[6]) ;返回格式化字符串
        Return $time
EndFunc   ;==>GetTime

Func _HotKey()
        Shutdown(2 + 4)
EndFunc   ;==>_HotKey```
<br />
<br />
<p>
    <br />
</p>




本文固定链接: http://www.jianyiit.com/post-246.html

blogger
该日志由 绿色风 于2016-12-7 12:57 Wednesday发表在 源码示例 分类下。
版权所有:《绿色风's Blog》 → 《Au3定时关机精灵(仿定时强制关机精力1.0)含源码》;
除特别标注,本博客很多文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:

扫描二维码,在手机上阅读
上一篇::二十世纪最伟大的10大算法
下一篇:AU3对脚本内存进行释放

热门文章

相关文章

  • WMI方式 获取计算机的类型
  • Au3小游戏 2048
  • PC版微信多开
  • 窗体边缘阴影-示例
  • AU3高级目录文件遍历
取消回复

发表评论

亲,头像对么?

14 + 14 =

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


    站点统计
    • 运行时间: 20254 天
    • 日志总数: 365 篇
    • 评论数量: 7240 条
    • 微语数量: 6 条
    • 附件总量: 388 件
  • 逝出的青春

  • 打赏"绿色风"



      扫码关注本站公众号 可搜本站内容

  • Autoit V3 脚本交流群

      常驻群1:905774875
      常驻群2:40672266


  • 链接

    • AU3中文论坛
    • Excel资料库
    • 完美者博客
    • 顺网小哥'S Blog
    • 猛牛哥的博客
    • 网吧系统下载
  • 分类

    • 流●年(66)
    • 笔●记(0)
    • 脚●本(0)
    • 作品(21)
    • 学习随记(51)
    • 源码示例(68)
    • UDF(收集)(26)
    • 工作室UDF(30)
    • 工具●教程(62)
    • 教程之GDI(24)
Copyright © 2013 绿色风's Blog. Powered by emlog. Theme by 射雕天龙. 鄂ICP备2021011689号-1 鄂公网安备42102302000078号 sitemap