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

[AU3基础] 求助定时读写文本文件---已解决

  [复制链接]
发表于 2011-9-20 09:51:12 | 显示全部楼层 |阅读模式
本帖最后由 txbihai 于 2011-9-30 22:44 编辑

是高手的一个定时器,我想改为定时每60秒写一次time.txt文件。
而且文件不能被关掉或退出时必须有正确的密码。

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>

$time=IniRead("config.ini","time","time","error")
$path1=IniRead("config.ini","setup1","path","error")
$path2=IniRead("config.ini","setup2","path","error");$time*
$time=1000*6
AdlibRegister("time",$time)

$Form1 = GUICreate("请耐心等待"&$time&"毫秒", 639, 460, -1, -1)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
Func time()
        MsgBox(0,"警告","定时启动程序已经启动"&@CRLF&$path1&@CRLF&$path2&@CRLF&$time)
               
EndFunc
发表于 2011-9-21 13:31:33 | 显示全部楼层
本帖最后由 gzh888666 于 2011-9-21 13:35 编辑

自己先写吧,到不会的时候再来询问!每60秒写一次time.txt看帮助就可以搞好的。参看循环实例和sleep函数 。
关闭提供一个思路,关掉文件之前先弹出一个密码框gui。用IF判断一下是否是某字符串密码,如果正确就退出,不正确就返回。希望对你有帮助。
发表于 2011-9-21 13:56:44 | 显示全部楼层
这个还是比较容易实现的
发表于 2011-9-21 21:17:46 | 显示全部楼层
额做了一下,定时器不会写
退出程序要密码这个我有

while 1
 $nMsg = GUIGetMsg()
        if $nMsg=$GUI_EVENT_CLOSE Then 
                        MsgBox("","warning","pls input the pwd to exit")                        
             if InputBox("pls type the pwd","pls input the password to exit the program","","*")="112233" Then ExitLoop
                
                EndIf
                
WEnd        
发表于 2011-9-21 22:31:24 | 显示全部楼层
        
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3> 

$Form1 = GUICreate("请耐心等待", 639, 460, -1, -1)
GUISetState()

local $i=0
Local $T_key="aabbcc"

                
   while 1
           $i=$i+1
            IniWrite("vfg.ini","PE EXPLORER"&$i,$T_key,$i)
                
                                                   
 $nMsg = GUIGetMsg()
        Select
            case $nMsg=$GUI_EVENT_CLOSE 
                        MsgBox("","warning","pls input the pwd to exit")        
                        $pwd=InputBox("pls type the pwd","pls input the password to exit the program","","*")
                        if $pwd="22" Then         Exit
                EndSelect
                        
                Sleep(2000)

WEnd


这个代码到是可以每隔多少时间写一次文件,但是窗体加入了sleep()就关不了了???
发表于 2011-9-21 22:48:21 | 显示全部楼层
本帖最后由 autt 于 2011-9-21 22:56 编辑

这个主要的难点(对我来说)差不多解决了,余下的应该就简单了


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3> 

$Form1 = GUICreate("请耐心等待", 639, 460, -1, -1)
GUISetState()

local $i=0
Local $T_key="aabbcc"
AdlibRegister("timer",2000)  ;2秒刷新一新
                
Func timer()
           $i=$i+1   ;这个是自己加的,为验证程序工作工常否
            IniWrite("vfg.ini","PE EXPLORER"&$i,$T_key,$i)  ;写文件,
        EndFunc
        
;以下为退出要使用密码,但是在任务栏中密码无效果,右键可直接退出...   

while 1                                   
 $nMsg = GUIGetMsg()
        Select
            case $nMsg=$GUI_EVENT_CLOSE 
                        MsgBox("","warning","pls input the pwd to exit")        
                        $pwd=InputBox("pls type the pwd","pls input the password to exit the program","","*")
                        if $pwd="22" Then         Exit
                EndSelect
WEnd
 楼主| 发表于 2011-9-25 19:38:38 | 显示全部楼层
谢谢各位大侠的热情,经过多次的调试终于搞好了定时读文本文件把有新的内容写到EXCEL表里.
下面是检测程序是否已运行,如果已经运行了就隐藏并调用热键显示窗口.输入正确的密码程序可以安全退出.
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\WINDOWS\system32\shell32.dll|-48
#AutoIt3Wrapper_outfile=cz.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
Break(0)
$list=ProcessList("cz.exe")
If $list[0][0] >1 Then
;MsgBox(0,"系统提示","已运行,请不要重复运行!!")
Exit
EndIf

HotKeySet("{F8}", "ts")
Func ts()
        If BitAND(WinGetState($Form1),2) <> 2 then
        ;endif
        GUISetState(@SW_SHOW)
else
        $pass = InputBox("请输入密码退出:","提示:15秒后该窗口自动关闭","","*M15",175,126,@DesktopWidth/2-150,@DesktopHeight/2-150,15)
        if $pass = "37330637" then Exit
        GUISetState(@SW_HIDE)
        endif
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-1 15:15 , Processed in 0.076201 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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