Visual Basic executables can access data appended to the .exe file after its creation. Here’s how:

1) Make the Visual Basic .exe file as usual.

2) Add the data to the end of the same .exe file. I use a second VB program to append the data. For example:

Private Sub Form_Load()
Dim FileSize&, FileName$, j%
FileName = "C:\MyApp.exe"
FileSize = FileLen(FileName)
Open FileName For Binary Access Write As #1
For j = 1 To 10
Put #1, FileSize + j - 1, CByte(Asc(Mid("It worked!", j, 1)))
Next j
Close
End Sub

3) When the .exe file is executed, it can read the data you have appended to that same .exe file. For example, if MyApp.exe is the executable produced from the following:

Private Sub Form_Load()
Dim FileSize&, FileName$, j%, OutputString$, InputByte As Byte
FileName = "C:\MyApp.exe"
FileSize = FileLen(FileName)
OutputString = ""
Open FileName For Binary Access Read As #1
For j = FileSize - 9 To FileSize
Get #1, j, InputByte
OutputString = OutputString & Chr(InputByte)
Next j
Close
MsgBox OutputString
End Sub

Then, after running the code under 2), execution of MyApp.exe pops the MsgBox “It worked!”

4) If the program run from the .exe file attempts to write to the .exe file, a run-time “access denied” error occurs. (Not surprising, but I thought I’d try!)



John Fritch