Kay,this is by nooooo means foolproof,but it should deter & protect against the average snooper, like your little sister,mom,or average roommate.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, force
#NoTrayIcon
#Persistent
pass := "moon"
dirWatchdog := Func("MonitorDir").Bind("c:\windows","c:\users")
SetTimer, % dirWatchdog, 500
MonitorDir(paths*){
Global pass,expID
Static authPaths
Try For index,path in paths
If (!InStr(authPaths,path) && InStr(Explorer_GetPath(),path)){
SoundPlay *16
SetTimer, ExplorerGuard, 100
WinGet, expID, ID
WinMinimize, ahk_id %expID%
pwd := InputBox2("ProtectedDir", "Input Password:", "pwd...",,,,,1,"green").input1
If (pwd <> pass)
WinClose, ahk_id %expID%
Else
authPaths .= authPaths ? "`n" path : path
SetTimer, ExplorerGuard, off
WinRestore, ahk_id %expID% ;if password was valid & win still exists...
}
}
ExplorerGuard(){ ;prevents user from switching away from password prompt to the explorer window...
Global
SetTimer, ExplorerGuard, off
If WinActive("ahk_id " expID){
WinClose, ahk_id %expID%
GuiDestroyAll() ;to destroy the input box...if user attempts to switch away from it to explorer window...
}
SetTimer, ExplorerGuard, on
}
GuiDestroyAll(){
DHW := A_DetectHiddenWindows
DetectHiddenWindows, On
PID := DllCall("GetCurrentProcessId", "UInt")
WinGet, GuiList, List, ahk_class AutoHotkeyGUI ahk_pid %PID%
Loop %GuiList%
Gui, % GuiList%A_Index% . ":Destroy"
DetectHiddenWindows, %DHW%
Return GuiList
}
InputBox2(title:="", inputBoxText1:="", inputBoxDefault1:="", inputBoxText2:="", inputBoxDefault2:="", x:="", y:="", ibPwd1:=0,ibPwd2:=0,titleColour:="Red"){
Static Input1, Input2
x := !x ? 3 : x, y := !y ? A_ScreenHeight//2 : y, (!inputBoxText2 && !inputBoxDefault2 ? (h:=30) & (yT:=2) : (h:=50) & (yT:=12))
,ibPwd1 := ibPwd1 ? "Password" : "", ibPwd2 := ibPwd2 ? "Password" : ""
Gui, -Sysmenu -Caption +Toolwindow +AlwaysOnTop +LastFound -Border +HwndGuiInputBoxHwnd
Gui, Margin, 0, 0
Gui, Color, black,black
Gui,Font,s11 cWhite ,Calibri
WinSet, Transparent, 200
gui, +toolwindow
If inputBoxText1
gui, add, text, x5 y4 w200 h20, % inputBoxText1
If inputBoxDefault1
gui, add, edit, x+4 y4 w180 h20 vInput1 %ibPwd1%, % inputBoxDefault1
If inputBoxText2
gui, add, text, x5 w200 h20, % inputBoxText2
If inputBoxDefault2
gui, add, edit, x+4 y24 w180 h20 vInput2 %ibPwd2%, % inputBoxDefault2
gui, add, button, hidden default x188 y4 w26 h20 gok, OK
Gui, Font, c%titleColour% s14 Bold, Calibri
gui, add, text, x400 y%yT% w100 h50, % title
Gui, Font
WinSet, Region, 0-0 w500 h%h% R10-10
Gui, show, x%x% y%y% w500 h%h%, Input(s)...
While WinExist("Input(s)...")
Sleep 10
Gui, destroy
ok:
gui, submit
inputs := Input1 "`n" (inputBoxDefault2 ? Input2 : "")
Gui, destroy
Return {inputs:inputs,input1:StrSplit(inputs,"`n")[1],input2:StrSplit(inputs,"`n")[2]}
}
/*
Library for getting info from a specific explorer window (if window handle not specified, the currently active
window will be used). Requires AHK_L or similar. Works with the desktop. Does not currently work with save
dialogs and such.
Explorer_GetSelected(hwnd="") - paths of target window's selected items
Explorer_GetAll(hwnd="") - paths of all items in the target window's folder
Explorer_GetPath(hwnd="") - path of target window's folder
example:
F1::
path := Explorer_GetPath()
all := Explorer_GetAll()
sel := Explorer_GetSelected()
MsgBox % path
MsgBox % all
MsgBox % sel
return
Joshua A. Kinnison
2011-04-27, 16:12
*/
Explorer_GetPath(hwnd="")
{
if !(window := Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
return A_Desktop
path := window.LocationURL
path := RegExReplace(path, "ftp://.*@","ftp://")
StringReplace, path, path, file:///
StringReplace, path, path, /, \, All
; thanks to polyethene
Loop
If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
Else Break
return path
}
Explorer_GetAll(hwnd="")
{
return Explorer_Get(hwnd)
}
Explorer_GetSelected(hwnd="")
{
return Explorer_Get(hwnd,true)
}
Explorer_GetWindow(hwnd="")
{
; thanks to jethrow for some pointers here
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process!="explorer.exe")
return
if (class ~= "(Cabinet|Explore)WClass")
{
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
return window
}
else if (class ~= "Progman|WorkerW")
return "desktop" ; desktop found
}
Explorer_Get(hwnd="",selection=false)
{
if !(window := Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
{
ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
if !hwWindow ; #D mode
ControlGet, hwWindow, HWND,, SysListView321, A
ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
Loop, Parse, files, `n, `r
{
path := base "\" A_LoopField
IfExist %path% ; ignore special icons like Computer (at least for now)
ret .= path "`n"
}
}
else
{
if selection
collection := window.document.SelectedItems
else
collection := window.document.Folder.Items
for item in collection
ret .= item.path "`n"
}
return Trim(ret,"`n")
}