You must select "Run only when the user is logged on".
Task Scheduler with Windows OLE Excel
Hi,
I got the code block in Perl below. I can run via Command and get the output result.
When I add a Task Scheduler via my Remote Desktop machine and I'm not getting any result.
I have Administrator on this system and below is my setting.
I did some search and folks said that these 2 folders need to create. I went ahead and create if it doesn't exist, it exists now but the script still doesn't output result.
C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
I trigger the task manual and no result either. Any one has a solution for this?
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $rand = int(rand(1000));
my $output_file = "C:\JSL\test_".$rand.".xls";
my $EXCEL = Win32::OLE->new("Excel.Application","Quit");
$EXCEL->{"Visible"} = 1;
$EXCEL->{DisplayAlerts}= 0;
my $Workbook = $EXCEL -> Workbooks -> Add();
my $sheet = $Workbook -> Worksheets(1);
$sheet->Range("A1")->{Value} = $rand;
$Workbook -> SaveAs($output_file);
$Workbook -> Save();
$EXCEL->Quit();
my $jmp = Win32::OLE->new('JMP.Application');
$jmp->{'Visible'}= 1;
my $dt = $jmp->NewDataTable("test_jmp.jmp");
my $col = $dt->NewColumn("Col1", 1, 0, 8);
$dt->Save("C:\JSL\test.jmp");
$jmp->Quit;
Win32::OLE->FreeUnusedLibraries();
Windows for home | Windows 10 | Settings
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
-
Anonymous
2021-04-09T16:29:32+00:00
6 additional answers
Sort by: Most helpful
-
Anonymous
2021-04-09T16:23:20+00:00 Frederik,
See two tasks screenshot and XML export below. Task2 provides an output file because there is no interaction with Excel or JMP.
Thanks.
Task1 XML
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2021-04-09T09:01:54.164493</Date>
<Author>DOMAIN2\HyRo</Author>
<URI>\task_schedule\Task1</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2021-04-09T08:31:24</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-725345543-602162358-527237240-995636</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Strawberry\perl\bin\perl.exe</Command>
<Arguments>C:\JSL\task_scheduler_run.pl</Arguments>
</Exec>
</Actions>
</Task>
Task2 XML
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2021-04-09T09:10:45.1348945</Date>
<Author>DOMAIN2\HyRo</Author>
<URI>\task_schedule\Task2</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2021-04-09T09:09:58</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-725345543-602162358-527237240-995636</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Strawberry\perl\bin\perl.exe</Command>
<Arguments>C:\JSL\task_scheduler_run2.pl</Arguments>
</Exec>
</Actions>
</Task>
Task1 Code
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $rand = int(rand(1000));
my $output_file = "C:\JSL\test_".$rand.".xls";
my $EXCEL = Win32::OLE->new("Excel.Application","Quit");
$EXCEL->{"Visible"} = 1;
$EXCEL->{DisplayAlerts}= 0;
my $Workbook = $EXCEL -> Workbooks -> Add();
my $sheet = $Workbook -> Worksheets(1);
$sheet->Range("A1")->{Value} = $rand;
$Workbook -> SaveAs($output_file);
$Workbook -> Save();
$EXCEL->Quit();
my $jmp = Win32::OLE->new('JMP.Application');
$jmp->{'Visible'}= 1;
my $dt = $jmp->NewDataTable("test_jmp.jmp");
my $col = $dt->NewColumn("Col1", 1, 0, 8);
$dt->Save("C:\JSL\test.jmp");
$jmp->Quit;
Win32::OLE->FreeUnusedLibraries();
Task2 Code
use strict;
use warnings;
my $rand = int(rand(1000));
my $output_file = "C:\JSL\test_".$rand.".txt";
open(FILEOUT,">$output_file");
print FILEOUT $rand;
close FILEOUT;
Op Codes Description
0 or 0x0 The operation completed successfully.
1 or 0x1 Incorrect function called or unknown function called.
2 or 0x2 File not found.
10 or 0xa The environment is incorrect.
0x41300 Task is ready to run at its next scheduled time.
0x41301 Task is currently running.
0x41302 Task is disabled.
0x41303 Task has not yet run.
0x41304 There are no more runs scheduled for this task.
0x41306 Task is terminated.
0x8004131F An instance of this task is already running.
0x800704DD The service is not available (is ‘Run only when a user is logged on’ checked?)
0xC000013A The application terminated as a result of a CTRL+C.
0xC06D007E Unknown software exception.
-
Anonymous
2021-04-09T15:50:14+00:00 I open up the Task Scheduler and trigger the task. The status said "Run" but never have any output result I'm expecting based on the script.
Please export the task, then paste the resulting .xml file into your reply.
-
Anonymous
2021-04-09T15:18:28+00:00 I open up the Task Scheduler and trigger the task. The status said "Run" but never have any output result I'm expecting based on the script.
-
Anonymous
2021-04-09T06:36:41+00:00 MS Office products require an interactive session to run. When you invoke your Perl task under your current account while logged on then it should run.