Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Password to open AHK ini file

  • Please log in to reply
2 replies to this topic
  • Members
  • 19 posts
  • Last active: Nov 19 2017 02:53 PM
  • Joined: 08 Nov 2005
I apologize for my limitations in advance...

Is it possible to add a script to my AHK ini file that will encrypt the .ini file when I close it, and then ask for a password when I open it, and then decrypt and load the ini file? Essentially, a password + encryption lock to hide everything in the script file, but still keep the .ahk extension so it will try to load when clicked on?

I am trying to avoid having to do a separate encryption/decryption every time I open AHK. I would need this in certain selected files, not every AHK file.

[VxE]'s Encryption Function is excellent, as are others, but I'm trying to find a shortcut. I am trying to promote AHK as a timesaver in my physicians' group, but a major concern is security of passwords. As it is, I'm by far the most "techie" person in the group, and even I have some difficulty negotiating some of the encryption utilities. What's needed is super simplicity: click on AHK.exe, enter password in box, file decrypts and loads. Close AHK => file encrypts and closes and is unreadable off the hard drive. Any takers?

If this has already been done, kindly point me to the post. And thanks to everyone for this great forum!

  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
You can save your scripts in a small TrueCrypt container.

autohotkey.com/net Site Manager


Contact me by email (polyethene at autohotkey.net) or message tidbit

  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Here's a short illustration of one way to go about having a script keep its ini file encrypted when not in use. It's not a working example, but it should give an idea or two. Another method would be to keep the key values encrypted and only decrypt them when they are being used.

OnExit, OnExitSubroutine

MyINIFile = %A_MyDocuments%\TestInfo.ini

; A snippet to read from an encrypted ini file
	InputBox, mypassword, What's my password !
	FileRead, InFile, %MyINIFile% ; read an encrypted ini file
	FileMove, %MyINIFile%, %MyINIFile%.tmp, 1 ; move the original out of the way
	FileAppend, % Decrypt(mypassword, InFile), %MyINIFile% ; write the decrypted file
	InFile := ""
	IniRead, Version, %MyINIFile%, The Top, Version, Error
	; ... whatever other inireads you need ...
	FileMove, %MyINIFile%.tmp, %MyINIFile%, 1
	If Version = Error ; the file failed to decrypt if the key wasn't read
		msgbox Wrong Password !

IfExist, %MyINIFile%.tmp
	FileMove, %MyINIFile%.tmp, %MyINIFile%, 1

; Example ini file:
; [The Top]
; Version=1.234.567
; [Data]
; Data1=Sir Lancelot
; Data2=To seek the grail
; Data3=Blue
; ...
; To encrypt an ini file, try the following steps
; after all the keys have been added to the file
FileRead, InFile, %MyINIFile%
FileAppend, % Encrypt(mypassword, InFile), %MyINIFile%.tmp
FileMove, %MyINIFile%.tmp, %MyINIFile%, 1
InFile := ""