How do I set the Run Task As credential on the TaskClass? - VisualCron - Forum

Community forum

Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Offline Archibald P. Weatherby  
#1 Posted : Thursday, March 16, 2017 5:07:23 PM(UTC)
Archibald P. Weatherby

Rank: No customer

Joined: 3/16/2017(UTC)
Posts: 3
Canada
Location: Ontario, Toronto

I am trying to set the credential on the ExecutionContext but I am not sure if that is the correct way to do this.

Below is the code we are using to create the new job and task and a screenshot of what we are attempting to do via the API:
https://www.screencast.com/t/bg9irb0i1x

Code:
    JobClass j = new JobClass();
            j.Group = server;
            j.Name = _mlsArea;
            j.Description = GetDropDownValue(arguments);

            // create interval trigger for last friday in month
            TriggerClass tr = j.AddTrigger(TimeClass.TimeTriggerT.Interval);

            tr.TTime.InitDate = timeTriger;
            tr.FirstRun = timeTriger;
            tr.TTime.IntervalType = TimeClass.IntervalT.Hourly;
            tr.TTime.IntervalValue = interval;
            tr.Description = String.Format("Every {0} Hours", tr.TTime.IntervalValue);

            TaskClass ta = new TaskClass();
            ta.StoreSTDOut = true;
            ta.StoreSTDErr = true;
            ta.Execute = new TaskExecuteClass();
            ta.Execute.CmdLine = @"M:\ApplicationCode\ProdEXE\ProdCopy\bin\ProdCopy.exe";
            ta.Execute.Arguments = arguments;
            ta.ExecutionContext.UserName = "mlsjobs";
            ta.Name = arguments;

            j.Tasks.Add(ta);

Edited by moderator Friday, March 17, 2017 11:47:09 AM(UTC)  | Reason: Not specified

Offline Support  
#2 Posted : Friday, March 17, 2017 11:46:50 AM(UTC)
Support

Rank: Official support

Joined: 2/23/2008(UTC)
Posts: 11,256

Thanks: 877 times
Was thanked: 450 time(s) in 427 post(s)
Hi,

it is this property:

Code:
ta.ExecutionContext.BeforeExecutionLogonCredential = credentialId;
Henrik
Support
http://www.visualcron.com
Please like VisualCron on facebook!
Offline Archibald P. Weatherby  
#3 Posted : Friday, March 17, 2017 3:31:23 PM(UTC)
Archibald P. Weatherby

Rank: No customer

Joined: 3/16/2017(UTC)
Posts: 3
Canada
Location: Ontario, Toronto

I've implemented your solution and I got the credential id from Server>Credentials>Copy Id to clipboard, but it still doesn't seem to be working. Am I missing anything else?

See Code below:
public JobClass CreateCronJob(string server, int interval, DateTime timeTriger, string arguments)
{
JobClass j = new JobClass();
j.Group = server;
j.Name = _mlsArea;
j.Description = GetDropDownValue(arguments);

// create interval trigger for last friday in month
TriggerClass tr = j.AddTrigger(TimeClass.TimeTriggerT.Interval);

tr.TTime.InitDate = timeTriger;
tr.FirstRun = timeTriger;
tr.TTime.IntervalType = TimeClass.IntervalT.Hourly;
tr.TTime.IntervalValue = interval;
tr.Description = String.Format("Every {0} Hours", tr.TTime.IntervalValue);

TaskClass ta = new TaskClass();
ta.StoreSTDOut = true;
ta.StoreSTDErr = true;
ta.Execute = new TaskExecuteClass();
ta.Execute.CmdLine = @"M:\ApplicationCode\ProdEXE\ProdCopy\bin\ProdCopy.exe";
ta.Execute.Arguments = arguments;
ta.ExecutionContext = new ExecutionContextClass();
ta.ExecutionContext.BeforeExecutionLogonCredential = "06c01f20-1a7e-4b82-b481-7c1c30b07ea6";
ta.Name = arguments;

j.Tasks.Add(ta);
return j;
Offline Archibald P. Weatherby  
#4 Posted : Friday, March 17, 2017 3:33:17 PM(UTC)
Archibald P. Weatherby

Rank: No customer

Joined: 3/16/2017(UTC)
Posts: 3
Canada
Location: Ontario, Toronto

I also have this issue and I'm not so sure it's related but every time I create a new job/task through the .Net API, Visual Cron on the server hangs at 50% and I need to kill the VisualCron Service and restart it in order to see the job created via the API.
Offline Support  
#5 Posted : Monday, March 20, 2017 8:51:54 PM(UTC)
Support

Rank: Official support

Joined: 2/23/2008(UTC)
Posts: 11,256

Thanks: 877 times
Was thanked: 450 time(s) in 427 post(s)
What I mean was that you perform serverObj.Jobs.Tasks.Update( after doing the change. Should not cause a hang.
Henrik
Support
http://www.visualcron.com
Please like VisualCron on facebook!
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Scroll to Top