找回密码
 加入
搜索
查看: 1906|回复: 2

哪个大大,帮忙改下删除的IF语句

[复制链接]
发表于 2009-2-9 10:39:34 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Version = 'AutoStartSettings'
If WinExists($Version) Then Exit
AutoItWinSetTitle($Version)

Global $Dll
Opt("OnExitFunc", "Quit")
FileInstall("SkinCrafterDll.dll", @TempDir & "SkinCrafterDll.dll", 1)
FileInstall("vista.skf", @TempDir & "vista.skf", 1)
$MainWindow = GUICreate("AutoStart Settings", 610, 303)
_SkinGUI(@TempDir & "SkinCrafterDll.dll", @TempDir & "vista.skf", $MainWindow)

#Region ### START Koda GUI section ### 
$Form1_1 = GUICreate("启动项设置工具", 632, 357, 193, 132, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), 0)
$Group1 = GUICtrlCreateGroup("每次启动有效列表", 16, 16, 305, 145)
$List1 = GUICtrlCreateListView("位置|名称| 路径", 24, 32, 289, 113)
GUICtrlSendMsg(1, $LVM_SETCOLUMNWIDTH, 0, 81)
GUICtrlSendMsg(1, $LVM_SETCOLUMNWIDTH, 1, 81)
GUICtrlSendMsg(1, $LVM_SETCOLUMNWIDTH, 2, 81)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($List1), 0, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($List1), 1, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($List1), 2, 2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("一次启动有效列表", 16, 168, 305, 145)
$List2 = GUICtrlCreateListView("位置|名称|路径", 24, 184, 281, 121)
GUICtrlSendMsg(1, $LVM_SETCOLUMNWIDTH, 0, 81)
GUICtrlSendMsg(1, $LVM_SETCOLUMNWIDTH, 1, 81)
GUICtrlSendMsg(1, $LVM_SETCOLUMNWIDTH, 2, 81)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($List2), 0, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($List2), 1, 2)
_GUICtrlListView_JustifyColumn(GUICtrlGetHandle($List2), 2, 2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("增加启动项", 336, 16, 273, 145)
$Label1 = GUICtrlCreateLabel("创建位置:", 352, 40, 55, 17)
$Label2 = GUICtrlCreateLabel("启动项名称:", 352, 80, 67, 17)
$Label3 = GUICtrlCreateLabel("启动项路径:", 352, 120, 67, 17)
$choose = GUICtrlCreateCombo("MACHINE → Run", 424, 40, 169, 25)
GUICtrlSetData(-1, "MACHINE → RunOnce|UNER → Run|USER → RunOnce")
GUICtrlSetTip(-1, "请选择您要添加的位置")
$name = GUICtrlCreateInput("Defalut", 424, 72, 169, 21)
GUICtrlSetTip(-1, "输入您要创建的启动项的名称")
$path = GUICtrlCreateInput("点击浏览选择文件...", 424, 112, 121, 21)
GUICtrlSetTip(-1, "输入您要创建的启动项的完整路径及文件名")
$Browse = GUICtrlCreateButton("浏览", 552, 112, 49, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Delete = GUICtrlCreateButton("删除(&D)", 336, 184, 105, 49, 0)
GUICtrlSetTip(-1, "删除已存在的启动项")
$Add = GUICtrlCreateButton("添加(&C)", 504, 184, 105, 49, 0)
GUICtrlSetTip(-1, "按您输入的名称和路径添加启动项")
$Refresh = GUICtrlCreateButton("刷新(&R)", 336, 256, 105, 49, 0)
GUICtrlSetTip(-1, "刷新启动项列表")
$About = GUICtrlCreateButton("关于(&A)", 504, 256, 105, 49, 0)
GUICtrlSetTip(-1, "关于。。。")
$Tips = GUICtrlCreateLabel("提示:组策略和开始菜单启动目录也可设置开机启动。", 336, 320, 283, 17)
GUICtrlSetState($Tips, $GUI_DISABLE)
GUISetState(@SW_SHOW)

$status = GUICtrlCreateLabel("", 16, 320, 320, 28)
GUISetState(@SW_SHOW)
Dim $Form1_1_AccelTable[4][2] = [["^d", $Delete],["^c", $Add],["^r", $Refresh],["^a", $About]]
GUISetAccelerators($Form1_1_AccelTable)
#EndRegion ### END Koda GUI section ###
Read()

While 1
        $Msg = GUIGetMsg()
        Select
                Case $Msg = $GUI_EVENT_CLOSE
                        Exit
                Case $Msg = $Browse
                        $PathValue = FileOpenDialog("请选择需要开机启动的文件...", @ScriptDir, "可执行文件(*.exe;*.bat;*.vbs)")
                        GUICtrlSetData($path, $PathValue)
                Case $Msg = $Add
                        $Data = GUICtrlRead($choose)
                        Select
                                Case GUICtrlRead($path) = "" Or GUICtrlRead($path) = "点击浏览选择文件..."
                                        MsgBox(0, "提示", "请输入正确的路径及文件名后再试!")
                                Case $Data = "MACHINE → RUN"
                                        RegWrite("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", GUICtrlRead($name), "REG_SZ", GUICtrlRead($path))
                                        MsgBox(0, "提示", "设置成功,重启生效!")
                                        Remain()
                                Case $Data = "UNER → Run"
                                        RegWrite("HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", GUICtrlRead($name), "REG_SZ", GUICtrlRead($path))
                                        MsgBox(0, "提示", "设置成功,重启生效!")
                                        Remain()
                                Case $Data = "MACHINE → RunOnce"
                                        RegWrite("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RunOnce", GUICtrlRead($name), "REG_SZ", GUICtrlRead($path))
                                        MsgBox(0, "提示", "设置成功,重启生效!")
                                        Remain()
                                Case $Data = "USER → RunOnce"
                                        RegWrite("HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RunOnce", GUICtrlRead($name), "REG_SZ", GUICtrlRead($path))
                                        MsgBox(0, "提示", "设置成功,重启生效!")
                                        Remain()
                        EndSelect
                Case $Msg = $Refresh
                        ReMain()
                Case $Msg = $About
                        About()
                Case $Msg = $Delete
                        If GUICtrlRead($List1) & GUICtrlRead($List2) = 0 Then
                                MsgBox(0, "提示", "请选择您需要删除的项目再进行操作!")
                        ElseIf GUICtrlRead($List1) & GUICtrlRead($List2) <> 0 Then
                                $answer = MsgBox(4, "提示", "删除后将不可恢复,只可手动添加,确认删除么?")
                                If $answer = 7 Then
                                        Remain()
                                Else
                                        If StringLeft(GUICtrlRead(GUICtrlRead($List1)), 4) = "User" Then
                                                $result = StringTrimLeft(GUICtrlRead(GUICtrlRead($List1)), 9)
                                                $x = StringInStr($result, "|")
                                                $y = StringLeft($result, $x - 1)
                                                RegDelete("HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", $y)
                                                GUICtrlDelete(GUICtrlRead($List1))
                                                MsgBox(0, "提示", "删除成功,重启生效!")
                                                Remain()
                                        Else
                                                $result = StringTrimLeft(GUICtrlRead(GUICtrlRead($List1)), 9)
                                                $x = StringInStr($result, "|")
                                                $y = StringLeft($result, $x - 1)
                                                RegDelete("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN", $y)
                                                GUICtrlDelete(GUICtrlRead($List1))
                                                MsgBox(0, "提示", "删除成功,重启生效!")
                                                Remain()
                                        EndIf
                                EndIf
                        EndIf
        EndSelect
        _ReduceMemory(@AutoItPID)
WEnd

Func Read()

        $Sum = 0
        $i = 1
        While 1
                $key = RegEnumVal('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', $i)
                If @error <> 0 Then ExitLoop
                GUICtrlCreateListViewItem('User    |' & $key & '|' & RegRead('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', $key), $List1)
                $i = $i + 1
                $Sum = $Sum + 1
        WEnd

        $i = 1
        While 1
                $key = RegEnumVal('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', $i)
                If @error <> 0 Then ExitLoop
                GUICtrlCreateListViewItem('Machine |' & $key & '|' & RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', $key), $List1)
                $i = $i + 1
                $Sum = $Sum + 1
        WEnd
        $i = 1
        While 1
                $key1 = RegEnumVal('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', $i)
                If @error <> 0 Then ExitLoop
                GUICtrlCreateListViewItem('user |' & $key1 & '|' & RegRead('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', $key1), $List2)
                $i = $i + 1
                $Sum = $Sum + 1
        WEnd
        $i = 1
        While 1
                $key1 = RegEnumVal('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', $i)
                If @error <> 0 Then ExitLoop
                GUICtrlCreateListViewItem('Machine |' & $key1 & '|' & RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', $key1), $List2)
                $i = $i + 1
                $Sum = $Sum + 1

        WEnd

        GUICtrlSetData($status, ' 读取启动项完毕! 共' & $Sum & '个项目...')
EndFunc   ;==>Read

Func ReMain()
        _GUICtrlListView_DeleteAllItems($List1)
        _GUICtrlListView_DeleteAllItems($List2)
        Read()
EndFunc   ;==>ReMain

Func About()
        GUISetState(@SW_DISABLE, $MainWindow)
        $Window = GUICreate("关于...", 235, 240)
        GUICtrlCreateIcon(@AutoItExe, -1, 22, 40)
        GUICtrlCreateGroup("", 8, 4, 220, 195)
        $Label1 = GUICtrlCreateLabel("启动项设置工具 V1.0", 70, 40, 142, 17, $WS_GROUP)
        GUICtrlSetFont(-1, 10, 800, 0, "宋体")
        GUICtrlCreateLabel("范统.贾", 70, 80, 100, 17)
        $Mail = GUICtrlCreateLabel("5i3p@sina.com", 70, 102, 100, 17)
        GUICtrlSetCursor($Mail, 0)
        GUICtrlSetColor(-1, 0x0000FF)
        GUICtrlCreateLabel("版权所有,盗版不究。", 20, 144, 124, 17, $WS_GROUP)
        GUICtrlCreateLabel("欢迎加入QQ群227200 (AU3技术交流)", 20, 168, 194, 17)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $OK = GUICtrlCreateButton("确定(&O)", 90, 208, 75, 25)
        GUISetState(@SW_SHOW)

        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                GUISetState(@SW_ENABLE, $MainWindow)
                                GUIDelete($Window)
                                ExitLoop
                        Case $OK
                                GUISetState(@SW_ENABLE, $MainWindow)
                                GUIDelete($Window)
                                ExitLoop
                        Case $Mail
                                Run(@ComSpec & " /c " & 'start mailto:5i3p@sina.com?subject=Something', "", @SW_HIDE)
                EndSwitch
        WEnd
EndFunc   ;==>About

Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
        $Dll = DllOpen($SkincrafterDll)
        DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1")
        DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1)
        DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin)
        DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25)
        DllCall($Dll, "int:cdecl", "ApplySkin")
EndFunc   ;==>_SkinGUI

Func quit()
        GUISetState(@SW_HIDE)
        DllCall($Dll, "int:cdecl", "DeInitDecoration")
        DllCall($Dll, "int:cdecl", "RemoveSkin")
        DllClose($Dll)
        FileDelete(@TempDir & "SkinCrafterDll.dll")
        FileDelete(@TempDir & "vista.skf")
        FileDelete(@TempDir & "eyes.jpg")
        Exit
EndFunc   ;==>quit

Func _ReduceMemory($i_PID = -1)
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf

        Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory
发表于 2009-2-10 12:51:04 | 显示全部楼层
晕,想怎么改,达到一个什么样的效果呢?
发表于 2009-2-10 15:06:08 | 显示全部楼层
没有任何要求,贴了代码就跑路?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-23 07:21 , Processed in 0.086933 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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