equinn
Posts: 2
Joined: Thu Apr 27, 2006 7:45 pm

uninstalling a directory

I am on my second day in using your product and I am very impressed. I am having a problem uninstalling my appdir directory though.

I have a product that creates a windows services and writes two text files. If I stop the service before uninstalling my product then the uninstaller deletes the entire directory structure (the installed files and the two created files by the service)---which is what I want.

If the service is still running when I uninstall my product, then everything except the two text files (including the subsequent directories in which they reside) are left, but everything else is deleted.

In the installexecutesequence area, I have created two vbs scripts under the stopservices and the deleteservices standard actions. I have also created a vbs scripts that removes my directory structure and linked to the removefolders standard actions.

Similar to a previous forum question...it is calling removeInstallDir function, with synchronous and ignore return, always execute, immediate, and remove=all.

Here is the script.

Function removeInstallDir()

Dim strComputer, objWMIService
Dim objFS, pathToFolder, smallPath

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set objFS = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

pathToFolder = Session.property("APPDIR")
smallPath=Left(pathToFolder,Len(pathToFolder)-1)
If (objFS.FolderExists(smallPath)) then
objFS.DeleteFolder smallPath, true
End if
End Function

I don't understand why the directory (specifically the two files) are not removed if the service is not running. Just to ensure if the application is holding the two files, I stopped the service, changed the text file names it made, and ran again and it won't delete the new or old named text files (this should test if the service is holding onto the text files).

Thanks
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

What I see from your post is that you use only one VBS script and this script doesn't stop any service. Here is what you can do to stop the service before the two files get deleted:

Add two "New Attached Custom Action" one under the "StopServices" standard action and another one under the "RemoveFolders" standard action. At the "Source Path" browse for the path of the VBS file. At the "Function Name" type the name of the function in the VBS file in our case: "stopService" or "removeInstallDir". As an "Execution Condition" choose "(REMOVE="ALL")" and leave other options to their default values.

Here is the two VBS files:

Code: Select all

Function stopService
	Dim objService, strComputer, objWMIService, colListOfServices, strService
	
	strComputer = "." 'this means local computer
	strService = " 'your service name' " 'do not change this sintax
										 'type heare your service name in case sensitive
	Set objWMIService = GetObject("winmgmts:" _
						& "{impersonationLevel=impersonate}!\\" _
						& strComputer & "\root\cimv2")
	Set colListOfServices = objWMIService.ExecQuery _
							("Select * from Win32_Service Where Name ="_
							& strService & " ")
	For Each objService in colListOfServices
		objService.StopService()
	Next
End Function

Code: Select all

Function removeInstallDir()
	Dim pathToFolder, smallPath
	Set objFS = CreateObject("Scripting.FileSystemObject")
	pathToFolder = Session.property("APPDIR")
	smallPath=Left(pathToFolder,Len(pathToFolder)-1)
	If (objFS.FolderExists(smallPath)) then
		objFS.DeleteFolder smallPath, true
	End if
End Function
Please let me know if you encounter any more problems.

Regards,
Gigi
__________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
equinn
Posts: 2
Joined: Thu Apr 27, 2006 7:45 pm

thanks for the quick response, but I already have those

Gigi,

I apologize for not listing out all the scripts I am using. I have a total of four scripts:
1) One that stops my service ---almost word for word with your script except for the ExecQuery for the Win32_Service I end with where Name='Myservice' "). As I stated earlier the script stops the service.
2) The second script I use deletes my service.
3) The third script is exactly like your uninstall function that is suppose to delete the directory structure.
4) The fourth script deletes a custom event log

What I don't understand is if my service is running and then I uninstall my product, it stops the service, deletes the service, and deletes the entire directory structure except those files the service created while it was running.

If I stop and start the service to create new files, therefore the service should not be "holding onto" any files, everything is deleted except all the files created...even the ones previously created when my service was running.

If my service is stopped, then the uninstall deletes my service and everything within the directory structure including any files the service created when it was running.

I don't know if this helps but under the Custom Actions/InstallExecuteSequence I have:
1) Uninstall Folder - The script to delete my custom event log is here
2) StopServices - The script to stop my service is here
3) DeleteServices - The script to delete my service is here
4) RemoveFolders - The script to delete my directory structure is here

They are all synchronous, ignore return colde, immediate execution, always execute, and Remove=All (except for the stop and delete service one...I tried adding that but it made no difference).

Do all of these run in order? Could it be that the removefolders is starting before my service has been stopped and deleted and if so how would I know or fix that?

Thanks,

Ed
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

If you provide a "Control Operation" for your service then it is controlled (started or stopped) by the Windows Installer so you don't need a VBS script to stop and delete this service because it gets stopped under the "StopServices" standard action.

All you need is a VBS script that deletes the files created by the service. This script needs to run after the service is stopped. Your service is stopped under the "StopServices" standard action and if you put an "Immediate execution" custom action under the "RemoveFolders" action it gets executed before the "StopServices" action because "Stop Services" is deferred and will be executed in order as part of the script built out of all the non-immediate actions.

To solve this create a "Property set with Formatted" under the "StopServices" action with the "Formatted Text" field set to "[APPDIR]" and edit the "Property Name" like this: "APPFOLDER" (for example). Add "New Attached Custom Action" under the "StopServices" action and name it with the "Property Name" from the "Property set with Formatted" custom action "APPFOLDER" in this case. Use following options for the second custom action:
1. Synchronous execution, ignore return code.
2. Deferred execution
3. Always Execute
4. REMOVE="ALL"

The script for the second CA looks like this:

Code: Select all

Function removeInstallDir()
	Dim pathToFolder, smallPath
	Set objFS = CreateObject("Scripting.FileSystemObject")
	pathToFolder = Session.property("CustomActionData")	
	smallPath=Left(pathToFolder,Len(pathToFolder)-1)		
	If (objFS.FolderExists(smallPath)) then
		objFS.DeleteFolder smallPath, true		
	End if
End Function
If this does not solve the problem please send us the log file to support at advancedinstaller dot com. Create the log with the following command line: msiexec /i package.msi /L*v c:\package.log

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”