Exam-70-486-Developing-ASP.NET-MVC-Web-Applications

Setup a script to open a timesheet on the Windows StartUp

To organize the progression, I will just setup a PowerShell script to initialize an excel timesheet on windows startup

In the PowerShell terminal, I will just run:

$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30

To set up a new 'trigger', at startup (-AtStartup parameter), with a delay of 30 seconds to avoid race condition

Now, I will relate the trigger with the file, just run the command:

Register-ScheduledJob -Trigger $trigger -FilePath C:\GitHub\Exam-70-486-Developing-ASP.NET-MVC-Web-Applications\Public\inicializacao.ps1 -Name StartingExcel

The expected output is: image

After rebooting, you can run Get-Job to verify the status

Now I will set the PowerShell script, it will open the excel timesheet on startup:

$FilePath = "C:\GitHub\Exam-70-486-Developing-ASP.NET-MVC-Web-Applications\Private\horariosestudo.xlsx"
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$Workbook = $Excel.Workbooks.Open($FilePath)

When I try to open it, I received an error

image

I just set the Execution Policy to AllSigned, and set a new signature, then I sign the script and run it.

References:

https://stackoverflow.com/questions/37665118/how-to-open-excel-workbook-from-powershell-for-automation https://devblogs.microsoft.com/scripting/use-powershell-to-create-job-that-runs-at-startup/ https://docs.microsoft.com/pt-br/powershell/module/microsoft.powershell.security/set-authenticodesignature?view=powershell-7.2 https://adamtheautomator.com/how-to-sign-powershell-script/