cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete/Disable a Scheduled Task Using an InstallScript Custom Action

Delete/Disable a Scheduled Task Using an InstallScript Custom Action

Introduction

This article explains the process of deleting or disabling a scheduled task before installing with a new installer using a Custom Action in an InstallScript project.

Instructions

When installing with a new installer, if an existing scheduled task is running, the installer will fail to created a new task. In order to create a scheduled task without any issues, first, we should disable or delete the existing scheduled task running on the target machine.

Please follow the steps below to delete or disable an existing scheduled task.

  1. Create an Installscript project.
  2. Add files under the Files and Folders View.
  3. Go to the InstallScript View under Behavior and Logic.
  4. Select the setup.rul.
  5. Select the righthand pane.
  6. Add the following InstallScript code:

 

 

 

function OnBegin()
STRING szMyPath, szCmdPath, szMyCmd, svProgramData, szMyPath2, szCmdPath2, szMyCmd2;
NUMBER nvBufferSize;
begin
szMyPath2 = "\"" + "for /f %x in ('schtasks /query ^| findstr test') do schtasks /Delete /TN %x /F" + "\"";
szCmdPath2 = WINSYSDIR ^ "cmd.exe";
szMyCmd2 = "/c " + szMyPath2;

MessageBox("szMyPath2=" + szMyPath2, INFORMATION);
MessageBox("szCmdPath2=" + szCmdPath2, INFORMATION);
MessageBox("szMyCmd2=" + szMyCmd2, INFORMATION);

LAAW_SHELLEXECUTEVERB="runas";
LaunchApplication(szCmdPath2, szMyCmd2, "", SW_HIDE, INFINITE, LAAW_OPTION_USE_SHELLEXECUTE | LAAW_OPTION_WAIT);
end;

 

A working sample project that demonstrates this functionality is attached to this article.

More Information

Click here to access the InstallScript Language Reference.

No ratings
Version history
Last update:
‎Feb 23, 2024 03:36 PM
Updated by:
Contributors