Hello Nick,
First of all, please accept my apologies for such a delayed reply.
You can execute your custom action after a reboot through a Windows Scheduled Task. For instance, you can wrap up your custom action in the form of a script file and execute it at the next log-on.
Here is a possible way in which you can achieve what you want:
- first of all, we will need to create a .BAT file that will do what you need (e.g. deletes a specific folder)
- upon uninstallation, we will have a custom action that will do the following:
1. set the REBOOT property to FORCE
2. creates a scheduled task that calls cmd.exe and invokes the .BAT file
Important: Besides containing your logic, the .BAT file should also delete the scheduled task after it executes (we want the scheduled task to execute only once).
The above leads to the following: in order to create and delete a scheduled task, one must have elevated privileges (administrator privileges). With that in mind, the
"Run as administrator"option should be checked in the
"Install Parameters" page & the user should be an administrator.
The .BAT file should be added in your package (in
"Files and Folders" page) as a
temporary file. After adding the file, please double click on it and check the
"Do not remove the file when setup ends" option. In addition to this, please pay attention to its
"Property" field as this is the property that stores the .BAT file path (which we will further use in our script).
Now that the .BAT file was correctly added to the project, it is time to create the custom action that further creates the scheduled task.
Quick Info: Task Scheduler is a component of Microsoft Windows that provides the ability to schedule the launch of programs or scripts at pre-defined times or after specified time intervals.
Basically, what I have until now (in my tests) is a .BAT file that looks as it follows:
Name: test.bat
Content:
Code: Select all
mshta.exe vbscript:Execute("msgbox ""HelloWorld"",0,""HelloMsgBox"":close")
schtasks.exe /DELETE /TN MyTask /F
All it does is to spawn a message box and then delete a scheduled task named "MyTask".
Now coming back to our main script. Besides setting the REBOOT property to FORCE, your custom action should also create a scheduled task that runs the earlier mentioned .BAT file. In my testing, I have used a PowerShell script that does that. The script is as it follows (
please use it as an example only - as I am not quite sure this is a production-ready script):
Code: Select all
# Block for declaring the script parameters.
Param()
# Your code goes here.
$bat = AI_GetMsiProperty AI_TEST.BAT
$schTaskAction = New-ScheduledTaskAction -Execute cmd.exe -Argument "/k $bat"
$trigger = New-ScheduledTaskTrigger -AtLogOn
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
$schTask = New-ScheduledTask -Action $schTaskAction -Trigger $trigger -Principal $principal
Register-ScheduledTask -TaskName MyTask -InputObject $schTask
AI_SetMsiProperty REBOOT FORCE
The script can be added through a
PowerShellScriptInline custom action,
with sequence, scheduled after the
"Finish Execution" action group.
The above script will create a scheduled task that will run the .BAT file at the next LogOn. This bat file firstly executes its logic and then deletes the scheduled task.
The .BAT file is launched using the
"/k" argument, which means "launch cmd.exe, execute the .BAT file and then wait for user input". If you want the command line interpreter to terminate automatically, you could use the
"/c" parameter instead.
As explained above, all of these tasks require the user running the custom aciton (implicitly running the uninstall process) to be an administrator.
Hope you will find this information useful.
Best regards,
Catalin