I have an app which run on a VM via a task scheduler. And the app tries to write to the credential manager but fails with error code 1312. The way I start my app on VM from host machine is via code:
$password= "password" | ConvertTo-SecureString -asPlainText -Force;
$username = "name";
$credential = New-Object System.Management.Automation.PSCredential($username,$password);
Invoke-Command -VMName INSTANCE_ID -Credential $credential -ScriptBlock
{
$gettime = (Get-Date).AddMinutes(2);
$run = $gettime.ToString('HH:mm');
$action = New-ScheduledTaskAction -Execute 'C:\logging.bat';
$trigger = New-ScheduledTaskTrigger -Once -At $run;
$setting = New-ScheduledTaskSettingsSet -Priority 4
$principal = New-ScheduledTaskPrincipal -GroupID "BUILTIN\Administrators" -RunLevel Highest;
Register-ScheduledTask -Action $action -Trigger $trigger -Setting $setting -Principal $principal -TaskName "ID_Logging_Task" -Description "my description"
}
As per understanding I am running with the highest privilege possible plus I have logged onto the VM via sysinternal autlogon tools. I don't understand what is going wrong here. What setting needs to be changed so that it can find a proper log on session.
UPDATE:
I added
$principal = New-ScheduledTaskPrincipal -UserID "DOMAIN\USERNAME" -LogonType Interactive -RunLevel Highest
with same username in Register-ScheduledTask
without password as when I specify password my app does not launch in interactive mode but as a background process. I need to fix 1312 error while running my app in interactive mode and in the highest privilege.