Password protect uninstallation of application

Hi All,

This is a tough one. I'd give more points if I could.

I want the Uninstaller (not VB's uninstaller) to prompt for a password (password would be the Admin password of the application itself, which is setup the first time my app is run, stored and encrypted in the registry), prior to performing the uninstallation.

Anyhow, I've used Inno Setup to create my setup file. If anyone is familiar with this setup utility, and could assist me here, I would be forever grateful.

I imagine it would take some tweaking of the compiled Uninstallation .dat file....quite the difficult task.

Who is Participating?
As ryancys said,what is to prevent the user from deleting the files? If you still want to password the uninstall here is an idea that will work.

The concept here is to create a seperate password app and write the Inno unistall file onto the end of it. Then when Inno unistall is run,your app will run where you can verify password.If the password is correct, read the inno unistall file data out of the password app and launch. If you want to try this add this routine to your main app to be run after install:

' command button shown for example,you would only want to call this
' routine once after installation
Private Sub Command1_Click()
WeldUninstallFile "unins000.exe", "Passwd.exe"
End Sub

Private Sub WeldUninstallFile(InnoUninstFile As String, PasswdApp As String)
Dim uFileData As String
Dim Pntr As Long, ff As Integer

' open inno uninstall file and read into uFileData
ff = FreeFile
Open InnoUninstFile For Binary Access Read As #ff
uFileData = Space(LOF(ff))
Get #ff, , uFileData
Close #ff

' write uFileData to the back of the password app
ff = FreeFile
Open PasswdApp For Binary Access Write As #ff
Pntr = LOF(ff) + 1
Put #ff, Pntr, Chr$(0) & "<--->" & uFileData ' <---> used as a delimiter
Close #ff

' kill the original inno unistall.exe
Kill InnoUninstFile

' rename password app as inno unistall file
Name PasswdApp As InnoUninstFile

End Sub

Then create a seperate exe to be installed with inno.Compile it and call it passwd.exe

' add 1 textbox called txtPasswd and a command button called cmdOk.
' Compile into Passwd.exe and install to the same directory as your app.

Private Sub cmdOk_Click()
' simple password validation example,replace with your code
' to read from registry
If txtPasswd = "MYPASSWORD" Then
    SpitOutUninstallFile "Uninstall.exe"
End If
End Sub

Private Sub SpitOutUninstallFile(OutputFileName As String)
Dim uFileData As String, mFile As String, arrDat() As String
Dim InnoDat As String, NewDat As String, ff As Integer

If Right$(App.Path, 1) <> "\" Then
    mFile = App.Path & "\" & App.EXEName & ".exe"
    InnoDat = App.Path & "\unins000.dat"
    mFile = App.Path & App.EXEName & ".exe"
    InnoDat = App.Path & "unins000.dat"
End If

' Open This exe file and read binary data into uFileData
ff = FreeFile
Open mFile For Binary Access Read As #ff
uFileData = Space(LOF(ff))
Get #ff, , uFileData
Close #ff

' split file data to get Uninstall file out
arrDat = Split(uFileData, "<--->")

' create new Uninstall File
ff = FreeFile
Open OutputFileName For Binary Access Write As #ff
Put #ff, , arrDat(1)
Close #ff

' get name for new dat file,it must match inno's uninst name w/ .dat ext
NewDat = Left$(OutputFileName, InStrRev(OutputFileName, ".") - 1) & ".dat"

' rename inno dat to new dat name
Name InnoDat As NewDat

' call the extracted Uninstall file
Shell OutputFileName, vbNormalFocus

End Sub

Ryan ChongCommented:
You can't, as the files installed on your machine can be deleted physically if you want to delete it manually. You can't prevent a user to delete your installed files, UNLESS you set the permission so that your logon user cannot delete the application files you had installed.
knuckle05Author Commented:
Hey vinnyd79,

Thanks for this suggestion, I will try it out ASAP and report back here.

I understand that someone could just delete the physical files from the drive, the thing is, there are some other "monitor type" services installed with my program that aren't easily detectable as I install them in the system folder.

The application I wrote is a web browser for kids, and included with it is a monitoring service that blocks the use of IE  and / or other mainstream browsers.

With a password protected uninstall file, this will at least preserve these monitors that run at startup. Not to say that they still couldn't be bypassed, I mean, they do show up as a running process in the task manager....anyhow, thx for your help, and I'll post back soon!
knuckle05Author Commented:

Pure genius!

It works mint, I had to make a few small additions, specifically some error handling in case I cancelled the process (as it would leave files behind) but it works great!

Question: It seems fairly simple to just weld the 2 together, but how come appending the original Inno setup file to the back of my PW app did not cause the EXE to crash? I was really surprised that it worked...

I'm really curious as to how you came up with this solution...pls give me some insight.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.