找回密码
 加入
搜索
查看: 7301|回复: 17

[AU3基础] (已解决)ini配置文件路戏检测问题

 火.. [复制链接]
发表于 2010-8-10 10:38:29 | 显示全部楼层 |阅读模式
本帖最后由 xargw 于 2010-8-10 13:08 编辑

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$config_file=@SystemDir&"\zhb.ini" ;定义变量=c:\windows\system32\zhb.ini
If FileExists($config_file) Then
        ;MsgBox(0,"提示","文件已存在")
Else
        $msgbox=MsgBox(4+64,"提示",$config_file&"配置文件不存在"&@CRLF & @CRLF &"是否要生成配置文件")
        Select
                Case $msgbox=6
                        $program=FileOpenDialog("请选择QQ启动文件","","可执行文件(*.exe)",1+1)
                        If Not @error Then IniWrite($config_file,"config","path",$program)
                Case $msgbox=7
                        Exit
        EndSelect
EndIf
$Form1 = GUICreate("Form1", 297, 209, 192, 114)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 112, 72, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 120, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If GUICtrlRead($checkbox1)=$gui_checked Then
                                $var=IniRead($config_file,"config","path","")
                            If $var="" Then
                                   MsgBox(0,"提示","请先配置文件")
                                   Exit
                            Else
                                   Run ($var)
                                EndIf
                               
                        Else
                                MsgBox(0,"提示","未选中")
                        EndIf

        EndSwitch
WEnd
如果勾选框选中后,配置文件路径不对(也就是不能启动文件,那么弹出选择文件对话框,其实就是要用一个检查path路径中的文件,是否存在,存在就ok,不存在就重新配置,并弹出文件对话框(用哪个命令检测啊)

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-8-10 10:52:51 | 显示全部楼层
FileExists
--------------------------------------------------------------------------------

检查指定文件或目录是否存在.


FileExists ( "路径" )




参数

路径 要检查的文件或目录的路径.



返回值

成功: 返回值为1.
失败: 返回值为0,说明指定的路径/文件并不存在.


用这个试试
发表于 2010-8-10 10:54:34 | 显示全部楼层
不好意思,改动了很多地方,希望对你有帮助。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$config_file = @ScriptDir & "\zhb.ini" ;定义变量=c:\windows\system32\zhb.ini
If FileExists($config_file) = 0 And MsgBox(4 + 64, "提示", $config_file & "配置文件不存在" & @CRLF & @CRLF & "是否要生成配置文件") = 6 Then
        IniWrite($config_file, "config", "Path", StringRegExpReplace(RegRead('HKCU\Software\Classes\Tencent', 'URL Protocol'), '(.+\\)[^\\]+', '\1QQ.exe'))
EndIf

$Form1 = GUICreate("Form1", 300, 200)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 112, 72, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 120, 128, 75, 25)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        Exit
                Case $Button1
                        If GUICtrlRead($Checkbox1) = $gui_checked Then
                                Run(IniRead($config_file, "config", "path", ""))
                        Else
                                MsgBox(0, "提示", "未选中")
                        EndIf
        EndSwitch
WEnd

评分

参与人数 1威望 +2 收起 理由
afan + 2

查看全部评分

 楼主| 发表于 2010-8-10 10:56:59 | 显示全部楼层
这个文件我查到了,问题是要怎么配合ini中path再查找对应的盘符下的文件夹下的文件是否存在!!
而不是直接去查,打个比方,人家有些人装QQ在C盘,有些装D盘,配置文件不对,肯定启动不了啊
发表于 2010-8-10 11:02:20 | 显示全部楼层
楼主是要做QQ登陆器吗?
 楼主| 发表于 2010-8-10 11:11:50 | 显示全部楼层
也不是说做登陆器,只不过是一个假设,如何获取ini中path路径是否正确,不正确就重新配置
发表于 2010-8-10 11:16:42 | 显示全部楼层
用IniRead读取ini文件中path的值
用FileExists检测文件是否存在
不是要这样的么?

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-8-10 11:17:03 | 显示全部楼层
现在我的要求是,点了按钮后,如果zhb.ini中的path路径不对,就要到这一步了$program=FileOpenDialog("请选择QQ启动文件","","可执行文件(*.exe)",1+1)
发表于 2010-8-10 11:28:24 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$config_file=@ScriptDir&"\zhb.ini" ;定义变量=c:\windows\system32\zhb.ini


Global $program
                                        
If FileExists($config_file) Then
        ;MsgBox(0,"提示","文件已存在")
Else
        $msgbox=MsgBox(4+64,"提示",$config_file&"配置文件不存在"&@CRLF & @CRLF &"是否要生成配置文件")
        Select
                Case $msgbox=6
                                                xuanze()
                Case $msgbox=7
                        Exit
        EndSelect
EndIf
$Form1 = GUICreate("Form1", 297, 209, 192, 114)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 112, 72, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 120, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If GUICtrlRead($checkbox1)=$gui_checked Then
                                $var=IniRead($config_file,"config","path","")
                                                                $q = FileExists($var)
                                                                If $q = 0 Then
                                                                        xuanze()                                                                        
                                                                        Run ($program)
                            Else 
                                   Run ($var)
                                EndIf
                                
                        Else
                                MsgBox(0,"提示","未选中")
                        EndIf

        EndSwitch
        WEnd
        
                Func xuanze()
                                                $program=FileOpenDialog("请选择QQ启动文件","","可执行文件(*.exe)",1+1)
                        If Not @error Then IniWrite($config_file,"config","path",$program)
                                        EndFunc
        
随便在你的代码上改了下

评分

参与人数 1贡献 +2 收起 理由
afan + 2

查看全部评分

 楼主| 发表于 2010-8-10 11:44:18 | 显示全部楼层
楼上兄弟,不对啊,第一次要配置,而后,不然配置文件在不在,都可以启动QQ
 楼主| 发表于 2010-8-10 11:54:59 | 显示全部楼层
先建立ini,而后防止别人,把QQ的路径安装在其它盘,从而需要检测ini中path中的路径是否正确,不正确就重新配置
发表于 2010-8-10 12:07:42 | 显示全部楼层
第一次运行是有配置的啊- -
 楼主| 发表于 2010-8-10 12:20:44 | 显示全部楼层
我的要求是,第一次提示配置,以后再运行就测试ini中path中的路径是否正确,正确就启动,不正确就打开FileOpenDialog("请选择QQ启动文件","","可执行文件(*.exe)",1+1)
然后保存,并启动
发表于 2010-8-10 12:26:20 | 显示全部楼层
我始终没明白楼主的意思!
照楼主的意思应该还需要有一个ini来记录这个路径,因为一旦路径被改又从怎么知道读取到的路径是否正确呢?
发表于 2010-8-10 12:41:24 | 显示全部楼层
回复 13# xargw


   
误导众生
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 364, 165, -1, -1)

$Button1 = GUICtrlCreateButton("启动QQ", 128, 88, 75, 25)

$ini = @ScriptDir&"\cfg.ini"

If FileExists($ini) = 0 Then
if msgbox(4,"","配置文件不存在,是否创建?") <> 6 then exit
IniWrite($ini, "QQ路径", "EXE", "B:\QQ2010\QQ.exe")
endif

GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                case $Button1
                        $exe = IniRead($ini, "QQ路径", "EXE", "")
                        If FileExists($exe) = 0 Then
                        $exe = FileOpenDialog("选择QQ程序位置", "", "执行程序(QQ.exe)")
                        If FileExists($exe) Then IniWrite($ini, "QQ路径", "EXE", $exe)
                        EndIf
                        If FileExists($exe) Then ShellExecute(IniRead($ini, "QQ路径", "EXE", ""))
        EndSwitch
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-2 22:16 , Processed in 0.127018 second(s), 30 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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