(已解决)ini配置文件路戏检测问题
本帖最后由 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,不存在就重新配置,并弹出文件对话框(用哪个命令检测啊) FileExists
--------------------------------------------------------------------------------
检查指定文件或目录是否存在.
FileExists ( "路径" )
参数
路径 要检查的文件或目录的路径.
返回值
成功: 返回值为1.
失败: 返回值为0,说明指定的路径/文件并不存在.
用这个试试 不好意思,改动了很多地方,希望对你有帮助。#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 这个文件我查到了,问题是要怎么配合ini中path再查找对应的盘符下的文件夹下的文件是否存在!!
而不是直接去查,打个比方,人家有些人装QQ在C盘,有些装D盘,配置文件不对,肯定启动不了啊 楼主是要做QQ登陆器吗? 也不是说做登陆器,只不过是一个假设,如何获取ini中path路径是否正确,不正确就重新配置 用IniRead读取ini文件中path的值
用FileExists检测文件是否存在
不是要这样的么? 现在我的要求是,点了按钮后,如果zhb.ini中的path路径不对,就要到这一步了$program=FileOpenDialog("请选择QQ启动文件","","可执行文件(*.exe)",1+1) #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
随便在你的代码上改了下 楼上兄弟,不对啊,第一次要配置,而后,不然配置文件在不在,都可以启动QQ 先建立ini,而后防止别人,把QQ的路径安装在其它盘,从而需要检测ini中path中的路径是否正确,不正确就重新配置 第一次运行是有配置的啊- - 我的要求是,第一次提示配置,以后再运行就测试ini中path中的路径是否正确,正确就启动,不正确就打开FileOpenDialog("请选择QQ启动文件","","可执行文件(*.exe)",1+1)
然后保存,并启动 我始终没明白楼主的意思!
照楼主的意思应该还需要有一个ini来记录这个路径,因为一旦路径被改又从怎么知道读取到的路径是否正确呢? 回复 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
页:
[1]
2