Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Opt("TrayMenuMode", 3)
- Opt("WinTitleMatchMode", 2) ; 1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
- Opt("WinDetectHiddenText", 1) ; 0=don't detect, 1=do detect
- Local $SleepTime = 100
- Local $KeePass[2] = ["C:\Program Files\KeePass Password Safe 2\", "KeePass.exe"]
- If $CmdLine[0] > 1 Then
- For $i = 1 to $CmdLine[0]
- Switch $CmdLine[$i]
- Case '-delay'
- $SleepTime = $CmdLine[$i + 1]
- Case '-path'
- $KeePass[0] = $CmdLine[$i + 1]
- Case '-name'
- $KeePass[1] = $CmdLine[$i + 1]
- EndSwitch
- Next
- EndIf
- Local $helpURL = "https://keepass.info/help/base/index.html"
- Local $AutoType[6] = ["-auto-type", "-auto-type-password", "-auto-type-selected", "--lock-all", "--unlock-all", "--exit-all"]
- Local $idKPsf = TrayCreateMenu("KeePass Password Safe")
- Local $idKP = TrayCreateItem("KeePass", $idKPsf)
- Local $idKPH = TrayCreateItem("KeePass Help", $idKPsf)
- Local $idQUIT = TrayCreateItem("Exit KeePass", $idKPsf)
- TrayCreateItem("")
- Local $idTOGL = TrayCreateItem("Lock or Unlock database")
- Local $idAT = TrayCreateItem("AutoType Selected")
- Local $idGAT = TrayCreateItem("Global AutoType")
- Local $idGATP = TrayCreateItem("Global PassWord")
- TrayCreateItem("")
- Local $idAG = TrayCreateMenu("AutoGAT++")
- Local $idRest = TrayCreateItem("Restart", $idAG) ; don't really need to use this anymore, but..
- Local $idExit = TrayCreateItem("Terminate", $idAG)
- TraySetState(1)
- While 1
- If Not ProcessExists($KeePass[1]) Then ExitLoop ;leaves this While loop if KeePass exits or isn't running
- If WinGetTitle("Locked") Then
- TraySetToolTip("AutoGAT++ database locked")
- TraySetIcon(@ScriptDir & '\AutoGAT_locked.ico')
- TrayItemSetState($idAT, 128) ;Menuitem will be greyed out
- TrayItemSetState($idGAT, 128) ;Menuitem will be greyed out
- TrayItemSetState($idGATP, 128) ;Menuitem will be greyed out
- TrayItemSetText($idTOGL, "Unlock database")
- Else
- TraySetToolTip("AutoGAT++")
- TraySetIcon(@ScriptDir & '\AutoGAT.ico')
- TrayItemSetState($idAT, 64) ;Menuitem will be enabled
- TrayItemSetState($idGAT, 64) ;Menuitem will be enabled
- TrayItemSetState($idGATP, 64) ;Menuitem will be enabled
- TrayItemSetText($idTOGL, "Lock database")
- EndIf
- Switch TrayGetMsg()
- Case -13 ;$TRAY_EVENT_PRIMARYDOUBLE
- ShellExecute($KeePass[0] & $KeePass[1])
- Case $idRest ; don't really need to use this anymore either, but..
- Restart()
- Case $idExit
- ExitLoop
- Case $idKP
- ShellExecute($KeePass[0] & $KeePass[1])
- Case $idKPH
- ShellExecute($helpURL)
- Case $idAT
- Send("!{TAB}")
- Sleep($SleepTime)
- ShellExecute($KeePass[0] & $KeePass[1], $AutoType[2])
- Case $idGAT
- Send("!{TAB}")
- Sleep($SleepTime)
- ShellExecute($KeePass[0] & $KeePass[1], $AutoType[0])
- Case $idGATP
- Send("!{TAB}")
- Sleep($SleepTime)
- ShellExecute($KeePass[0] & $KeePass[1], $AutoType[1])
- Case $idTOGL
- If TrayItemGetText($idTOGL) = "Unlock database" Then
- TraySetIcon(@ScriptDir & '\AutoGAT_locked.ico')
- TrayItemSetState($idAT, 64) ;Menuitem will be enabled
- TrayItemSetState($idGAT, 64) ;Menuitem will be enabled
- TrayItemSetState($idGATP, 64) ;Menuitem will be enabled
- ShellExecute($KeePass[0] & $KeePass[1], $AutoType[4]) ; Unlock
- Else
- TraySetIcon(@ScriptDir & '\AutoGAT.ico')
- TrayItemSetState($idAT, 128) ;Menuitem will be greyed out
- TrayItemSetState($idGAT, 128) ;Menuitem will be greyed out
- TrayItemSetState($idGATP, 128) ;Menuitem will be greyed out
- ShellExecute($KeePass[0] & $KeePass[1], $AutoType[3]) ; Lock
- EndIf
- Case $idQUIT
- ShellExecute($KeePass[0] & $KeePass[1], $AutoType[5])
- EndSwitch
- WEnd
- Exit
- Func Restart()
- ; Restart your program - http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=199608
- ; Author UP_NORTH
- If @Compiled = 1 Then
- Run(FileGetShortName(@ScriptFullPath))
- Else
- Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
- EndIf
- Exit
- EndFunc ;==>Restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement