When open multiple folders, ask user to enter password

Get help with using AutoHotkey and its commands and hotkeys
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

When open multiple folders, ask user to enter password

30 Nov 2018, 13:39

I want to protect some of the folders on my system: not just 1, but multiple..

I dont want to use several ahk scripts in those folders to monitor them and ask user to type in a password, i already found 1 that does that (see beneath)

so, when opening for example: c:\windows\system32 AND c:\program files the script should monitor those and ask the user to enter (1 time) to enter password.

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv
SetBatchLines, -1
DetectHiddenText, On
MyDocs = My Documents
SetTimer, Timer1, 100
Return
Gui:
Gui, +AlwaysOnTop -SysMenu +OwnDialogs
Gui, Font, s12 cRed, Arial Bold
Gui, Add, GroupBox, x10 y10 w305 h70, Vul het wachtwoord in
Gui, Font, s12 cBlack, Arial Bold
Gui, Add, Edit, vPassword x21 y40 w281 h25 Password
Gui, Add, Button, Default x10 y90 w305 h30, Enter
Gui, Show, Center w325, Deze map is wachtwoord beschermt
Return

ButtonEnter:
StringCaseSense, On
Gui, Submit
If Password = heregoesthepassword ;Change the word "Password" to the right of the equal(=) sign to your password.
{
SetTimer, Timer1, Off
Run C:\Windows\System
SetTimer, Timer2, 2000
}
Gui, Destroy
StringCaseSense, Off
Return

Timer1:
WinGetClass, Class, A
If Class contains CabinetWClass,ExploreWClass
{
	WinGetText, Text, A
	IfInString, Text, C:\Windows\System
	{
		WinClose, A
		WinActivate, This folder is password protected
		Loop, Parse, Text, `n, `r
		{
			Path = %A_LoopField%
			Break
		}
		If Path = C:\Windows\System
		Path = C:\Windows\System
		IfWinNotExist, This folder is password protected
		Goto, Gui
	}
}
Return


Timer2:
WinGet, Number_of_Windows, List,,, Program Manager
Loop, %Number_of_Windows%
{
ID := Number_of_Windows%A_Index%
WinGetClass, Class, ahk_id %ID%
If Class contains CabinetWClass,ExploreWClass
{
WinGetText, Text, ahk_id %ID%
IfInString, Text, C:\Windows\System
Cnt++
}
}
If Cnt = 0
{
SetTimer, Timer2, Off
SetTimer, Timer1, off
}
Cnt = 0
Return
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: When open multiple folders, ask user to enter password

01 Dec 2018, 12:00

Kay,this is by nooooo means foolproof,but it should deter & protect against the average snooper, like your little sister,mom,or average roommate.

Active Directory Protection.ahk

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")
}

live ? long & prosper : regards
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: When open multiple folders, ask user to enter password

01 Dec 2018, 12:29

well that looks very good :) thanx!

i trying to center the input password box....
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: When open multiple folders, ask user to enter password

01 Dec 2018, 12:36

loek3000 wrote:
01 Dec 2018, 12:29
well that looks very good :) thanx!

i trying to center the input password box....

Code: Select all

pwd := InputBox2("ProtectedDir", "Input Password:", "pwd...",,,xCentered := (A_ScreenWidth//2)*0.7,,1,"green").input1
live ? long & prosper : regards

Return to “Ask For Help”

Who is online

Users browsing this forum: 20170201225639, Google [Bot], IceBubble, mikeyww, necomerx, RyantheCoder, SAbboushi, viv and 37 guests