WinLock: Lock your windows and apps so only you can access them

Post your working scripts, libraries and tools for AHK v1.1 and older
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

WinLock: Lock your windows and apps so only you can access them

Post by EntropicBlackhole » 15 Oct 2021, 19:31

Ever wanted for someone to stop entering a certain app or window?
Do you want someone to stop entering your messages and seeing everything?
I got the solution for you!
I present to you: WinLock
An app made for locking windows and apps with a password that is encrypted, passwords can be up to 64 characters, use this and never worry about others entering certain windows without the password
please take a look at it this shit took too long to make
I don't 100% guarantee this will be fully efficient all the time, I've only tested the final script about 3 times, but it's enough, if you find any bugs tell me please I'm too lazy to do it myself

Code: Select all

#Persistent
#SingleInstance, Force
SetBatchLines, -1
activeWin := ""
Fol := "C:\Users\" A_UserName "\AppData\Local\EPBHs Creations\WinLock"
Set := Fol . "\Settings.ini"
Ini := Fol . "\WinLock.ini"
SP := false
Tips := ["Click me for more tips!", "To edit a password, delete and add", "Feel free to edit the script!", "My mother, EPBH made me!", "?t=11422"]
FileCreateDir, %Fol%
if !FileExist(Set)
{
	InputBox, GenPass, Winlock, It seems this is the first time you have ran this program.`nPlease enter a password to lock it.`n(No more than 64 characters), Hide, 240, 180
	if (ErrorLevel) || !(GenPass)
		ExitApp
	else
	{
		IniWrite, % Encrypt(GenPass, A_Programs), %Set%, Other, GenPass
		IniWrite, 1, %Set%, Other, Time
		IniWrite, F6, %Set%, Other, Hotkey
	}
}
IniRead, GenPass, %Set%, Other, GenPass
IniRead, Min, %Set%, Other, Time
IniRead, HK, %Set%, Other, Hotkey
if !FileExist(Ini)
	FileAppend, , %Ini%
Gui, Add, ListView, w400 h200 r20, WinName           |WinPass
GUi, Add, Button, gAddWin, Add Window
GUi, Add, Button, x+5 gDelWin, Delete Window
Gui, Add, Button, x+5 gSet, Settings
GUi, Add, Text, x288 yp+5 cRed, %Min%:00
Gui, Add, CheckBox, x+5 gShowPass vShowPass, Show Passwords
Gui, Show, , WinLock
Gui, New, , WinAdd
Gui, WinAdd:+ToolWindow
Gui, WinAdd:Add, Text, h40 +Center, Insert a password for WinTitle`nNo more than 64 characters
Gui, WinAdd:Add, Edit, w145 vPass Limit64 Password, 
Gui, WinAdd:Add, Button, y+5 gAddWin2 Default, OK
Gui, WinAdd:Add, Button, x+5 gCancel, Cancel
Gui, New, , Settings
Gui, Settings:+ToolWindow
Gui, Settings:Add, Text, x10 y10, General Password for WinLock`nNo more than 64 chars!
Gui, Settings:Add, Edit, w100 vGPass Disabled, %GenPass%
Gui, Settings:Add, Button, x+5 yp-1 gChangeGenPass, Change
Gui, Settings:Add, Text, xm, Minutes for passwords to appear
Gui, Settings:Add, Edit, w40 vMinutes, %Min%
Gui, Settings:Add, UpDown, , %Min%
Gui, Settings:Add, Text, , Hotkey for WinLock to appear
Gui, Settings:Add, Hotkey, vKH, %HK%
Gui, Settings:Add, Button, gApply, Apply
Gui, Settings:Add, StatusBar, gSB, % RandArr(Tips)
Gui, 1:ListView, SysListView321
Gui, 1:+hwndMain
GUi, 1:Default
IniRead, Names, %Ini%, Names
IniRead, Passwords, %Ini%, Passwords
Loop, Parse, Names, `n
{
	StringSplit, out, A_LoopField, =
	LV_Add(, out2)
}
Loop, Parse, Passwords, `n
{
	StringSplit, out, A_LoopField, =
	LV_Modify(A_Index, , , out2)
}
Hotkey, %HK%, Show
return

~LButton::
Sleep, 500
if (activeWin != WinActive("A")) 
{
	lastwin := activeWin
	activeWin := WinActive("A")
	WinGet, WinActive, ProcessPath, ahk_id %activeWin%
	IniRead, WinPassVar, %Ini%, Passwords, %WinActive%
	IniRead, WinNameVar, %Ini%, Names, %WinActive%
	if !(WinPassVar == "ERROR")
	{
		WinHide, ahk_id %activeWin%
		InputBox, thisshittooktoolongtomake, WinLock, Please insert your password for %WinNameVar%, , 135, 160
		if (thisshittooktoolongtomake = Decrypt(WinPassVar, A_Programs))
		{
			WinShow, ahk_id %activeWin%
			WinActivate, ahk_id %activeWin%
		}
		else
		{
			WinShow, ahk_id %activeWin%
			WinMinimize, ahk_id %activeWin%
		}
	}
}
return

Apply:
GUi, Settings:Submit
GPass := Encrypt(GPass, A_Programs)
IniWrite, %GPass%, %Set%, Other, GenPass
IniWrite, %Minutes%, %Set%, Other, Time
IniWrite, %KH%, %Set%, Other, Hotkey
GenPass := GPass
Min := Minutes
HK := KH
GuiControl, 1:, Static1, %Min%:00
return

Show:
Gui, 1:Show
return

SB:
SB_SetText(RandArr(Tips))
return

ChangeGenPass:
InputBox, GenPass, WinLock, Please enter your WinLock password, HIDE, 135, 145
Gui, Settings:Default
GuiControlGet, PassGen, Settings:, Edit1
Gui, 1:Default
if ErrorLevel
	return
else
{
	if (GenPass = Decrypt(PassGen, A_Programs))
	{
		GuiControl, Settings:Enable, Edit1
		GuiControl, Settings:Disable, Button2
		GuiControl, Settings:Text, Button1, Done
		GuiControl, Settings:Text, Edit1
		GuiControl, Settings:+gDoneSetGP, Button1
	}
	else
		MsgBox 0x30, Warning!, The password is incorrect.
}
return

DoneSetGP:
Gui, Settings:Submit, NoHide
GuiControl, Settings:Disable, Edit1
GuiControl, Settings:Enable, Button2
GuiControl, Settings:Text, Button1, Change
GuiControl, Settings:, Edit1, % Encrypt(GPass, A_Programs)
GuiControl, Settings:+gChangeGenPass, Button1
return

AddWin:
tt := "Go to the window you'd like to lock`nand press LCtrl once it's active"
SetTimer, ToolTip, 10
KeyWait, LControl, D
KeyWait, LControl
SetTimer, ToolTip, Off
ToolTip
WinGet, WinProcP, ProcessPath, A
WinGetTitle, WinTitle, A
GuiControl, WinAdd:Text, Static1, Insert a password for %WinTitle% `nNo more than 64 characters
GuiControl, WinAdd:MoveDraw, Static1
Gui, Show
Gui, WinAdd:Show
return

AddWin2:
Gui, WinAdd:Submit
GuiControl, WinAdd:, Edit1
if Pass
{
	Encrypt := Encrypt(Pass, A_Programs)
	IniWrite, %WinTitle%, %Ini%, Names, %WinProcP%
	IniWrite, %Encrypt%, %Ini%, Passwords, %WinProcP%
	Gui 1:Default
	LV_Add(, WinTitle, Encrypt)
}
return

DelWin:
if CheckItemSelected()
{
	LV_GetText(Name, CheckItem)
	LV_GetText(Pass, CheckItem, 2)
	InputBox, CheckPass, WinLock, Please enter your password for %Name%, HIDE, 135, 160
	if (CheckPass = Decrypt(Pass, A_Programs))
	{
		LV_GetText(WinTitle, CheckItem, 1)
		LV_GetText(WinPass, CheckItem, 2)
		MsgBox, 0x34, WinLock, Are you sure you want to delete %WinTitle%?
		IfMsgBox, Yes
		{
			IniRead, NamesIni, %Ini%, Names
			IniRead, PasswordsIni, %Ini%, Passwords
			Loop, Parse, NamesIni, `n
				if InStr(A_LoopField, WinTitle) && !(InStr(A_LoopField, "[Names]"))
					StringSplit, OutN, A_LoopField, =
			Loop, Parse, PasswordsIni, `n
				if InStr(A_LoopField, WinPass) && !(InStr(A_LoopField, "[Passwords]"))
					StringSplit, OutP, A_LoopField, =
			IniDelete, %Ini%, Names, %OutN1%
			IniDelete, %Ini%, Passwords, %OutP1%
			LV_Delete(CheckItem)
		}
		IfMsgBox, No
			return
	}
	if not CheckPass
		return
	if not (CheckPass = Decrypt(Pass, A_Programs))
		MsgBox 0x30, Warning!, The password is incorrect.
}
else
	MsgBox, 0x30, WinLock, Please select a row first.
return

Set:
Gui, Settings:Show
Gui, Settings:Default
SB_SetText(RandArr(Tips))
Gui, 1:Default
return

ShowPass:
Gui, Submit, NoHide
if ShowPass
{
	InputBox, GenPass, WinLock, Please enter your WinLock password, HIDE, 135, 145
	IniRead, PassGen, %Set%, other, GenPass
	if ErrorLevel
		return
	else
	{
		if (GenPass = Decrypt(PassGen, A_Programs))
		{
			GuiControl, Disable, Button1
			Loop, % LV_GetCount()↓
			{
				LV_GetText(txt, A_Index, 2)
				LV_Modify(A_Index, , , Decrypt(txt, A_Programs))
			}
			timers := 0
			timerm := Min
			SetTimer, StopWatch, 1000
		}
		else
		{
			MsgBox 0x30, Warning!, The password is incorrect.
			GuiControl, , Button4, 0
		}
	}
}
else
{
	SetTimer, StopWatch, Off
	GuiControl, Enable, Button1 
	GuiControl, , Static1, %Min%:00
	Loop, % LV_GetCount()
	{
		LV_GetText(txt, A_Index, 2)
		LV_Modify(A_Index, , , Encrypt(txt, A_Programs))
	}
}
return

Stopwatch:
timers -= 1
if (timers < 0)
{
	timerm -= 1
	timers := 59
	GuiControl, , Static1,  %timerm%:%timers%
}
if (timers < 10)
	GuiControl, , Static1,  %timerm%:0%timers%
else
	GuiControl, , Static1,  %timerm%:%timers%
if not timers && not timerm
{
	SetTimer, StopWatch, Off
	GuiControl, Enable, Button1 
	GuiControl, , Button4, 0
	GuiControl, , Static1, %Min%:00
	Loop, % LV_GetCount()
	{
		LV_GetText(txt, A_Index, 2)
		LV_Modify(A_Index, , , Encrypt(txt, A_Programs))
	}
}
return

ToolTip:
ToolTip, %tt%
return

Encrypt(Text, Key) {
	Loop, Parse, Text
		Encrypt .= Chr(((Asc(A_LoopField)-32)^(Asc(SubStr(Key,A_Index,1))-32))+32)
	return Encrypt
}
Decrypt(Text, Key) {
	Loop, Parse, Text
		Decrypt .= Chr(((Asc(A_LoopField)-32)^(Asc(SubStr(Key,A_Index,1))-32))+32)
	return Decrypt
}
CheckItemSelected() {
	global CheckItem
	TotalSelectedItems := % LV_GetCount("S")
	CheckItem := LV_GetNext()
	if (TotalSelectedItems >= 1)
		return true
	else
		return false
}
RandArr(Array) {
	Random, ArrRand, 1, % Array.MaxIndex()
	return Array[ArrRand]
}

User avatar
DataLife
Posts: 445
Joined: 29 Sep 2013, 19:52

Re: WinLock: Lock your windows and apps so only you can access them

Post by DataLife » 18 Oct 2021, 20:18

I must have done something wrong. I started the script and created a password for Winlock.ahk itself. I then added a window and chose a password.

When I start to open the protected window a Winlock password prompt opens. I ignore the password prompt and open my protected window anyway, even though I did not put in the protected window password.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

Post Reply

Return to “Scripts and Functions (v1)”