Share This Post:
Utilizing Windows Task Scheduler To Run GUI Applications From SYSTEM account
Editor Note: This article was published in 2014 but the content of this article is still relevant with recent Windows operating systems, such as Windows 10 and Windows server 2019. In addition, Voicent platform has moved towards browser interface and the spreadsheet-based programs have been obsoleted. However, the command line interface is still available and gets better. For more details, please see Campaign Interface and CRM interface.
——–
One of the security features of recent Windows (vista and later) is disabling running GUI applications from SYSTEM account (normally the processes running as Windows service). This adds some complications for Voicent IVR apps that utilize other Voicent programs, such as running BroadcastBySMS to send out text messages.
One nice workaround is to utilize Windows task scheduler. You can specify which program to run regardless of whether it is a console program or GUI program. In addition, you can specify the user account to run the program, the time to run, recurrence, and many other options. You can even start a program on a remote computer.
The following is a simple Windows batch file to run Voicent BroadcastBySMS program on a computer (COMP1) with user (U01) and password (P1234).
The task scheduler command
For more information about Windows Task scheduler command line options, please check the detailed document from Microsoft’s website. The main command line is as follows:
Schtasks /create /sc ScheduleType /tn TaskName /tr TaskRun [/s Computer [/u [Domain\]User [/p Password]]] [/ru {[Domain\]User | System}] [/rp Password] [/mo Modifier] [/d Day[,Day...] | *] [/m Month[,Month...]] [/i IdleTime] [/st StartTime] [/ri Interval] [{/et EndTime | /du Duration} [/k]] [/sd StartDate] [/ed EndDate] [/it] [/Z] [/F]
We will use the follow two commands, the first one cleans up any existing tasks:
Schtasks /delete /tn "Run BBS" /f /s COMP1 /u COMP1\U01 /p P1234
Schtasks /create /sc once /tn "Run BBS" /st %hh%:%mm% /s COMP1 /u COMP1\U01 /p P1234 /tr "\"C:\\Program Files (x86)\\Voicent\\BroadcastBySMS\\bin\\scase.exe\" -numbers \"%phoneno%\" -text \"Voicent Webinar will start in 15 minutes\" \"%soc%\"
The above command will schedule to run BroadcastBySMS once at the specified time %hh%:%mm% (more on this later), using the specified phone number %phoneno% and the specified soc file %soc%. The variables enclosed in % are Windows batch file variables.
Windows batch file
The sample batch file takes two arguments: the first one is the phone number, and the second is the .soc file for BroadcastBySMS. These two arguments are normally passed from your IVR app’s external program action.
set phoneno=%1
set phoneno=%phoneno:"=%
set soc=%2
set soc=%soc:"=%
The above lines take the two command line arguments, and remove the enclosing double quotes.
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (
set h=%%a
set m=%%b
)
REM remove leading 0
set /a mm=%m%
set /a mm=%mm% + 1
set /a hh=%h%
The above lines set the current hour and minute. Since it is possible to have leading zero for the number, variable hh and mm are used to hold the actual number. Here we use the /a command line switch to tell the system that %m% or %h% are numbers. We then add one minute to the current minute. Otherwise, the task scheduler may complain that the start time is too late.
if %mm% == 60 goto nexthour
goto checkmm
:nexthour
set /a hh=%hh% + 1
set mm=0
Just a few things to take care of if the current minute is 59. We need to advance the hour and set the minute to 0.
:checkmm
if %hh% lss 10 set hh=0%hh%
if %mm% lss 10 set mm=0%mm%
Then we add the leading zero back to the hour and minute if needed. Now we are ready to call the two windows task scheduler command as shown above. The whole batch file is shown below:
set phoneno=%1
set phoneno=%phoneno:"=%
set soc=%2
set soc=%soc:"=%
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (
set h=%%a
set m=%%b
)
REM remove leading 0
set /a mm=%m%
set /a mm=%mm% + 1
set /a hh=%h%
if %mm% == 60 goto nexthour
goto checkmm
:nexthour
set /a hh=%hh% + 1
set mm=0
:checkmm
if %hh% lss 10 set hh=0%hh%
if %mm% lss 10 set mm=0%mm%
schtasks /delete /tn "Run BBS From Workflow" /f /s COMP1 /u COMP1\U01 /p P1234
schtasks /create /sc once /tn "Run BBS From Workflow" /st %hh%:%mm% /s COMP1 /u COMP1\U01 /p P1234 /tr "\"C:\\Program Files (x86)\\Voicent\\BroadcastBySMS\\bin\\scase.exe\" -numbers \"%phoneno%\" -startnow -text \"webinar starts in next 15 minutes\" \"%soc%\""
You should be able to use the above script in your IVR app. Just make sure to change the computer name, user name, and password used in the script.
Share This Post: