How to autostart a video in Windows

The other day a friend asked me to help with a practical prank. For his girlfriend, he prepared a laptop as a gift, however he wanted to tease her a bit by automatically starting a scary video whenever she logs in.

Creating the scary code

For this to achieve creating a powershell script was the pragmatic solution. The corresponding code snippet is only three lines of code:

C:\'Program Files'\VideoLAN\VLC\vlc.exe --fullscreen --no-osd D:\Documents\hd1967.mov
sleep 2
Stop-process -Name vlc
  • 1st row:
    • path to the program which is about to be executed (in our case it is the vlc player),
    • –fullscreen : vlc option to open the video in fullscreen
    • –no-osd: vlc option to open the video without showing the title of the video
    • the absolute path to the media. Just in case it is best to have the absolute path to the source in quotes to prevent any problems with spaces in folder names
  • 2nd row
    • wait 2 seconds
  • 3rd row
    • a .NET specific functionality which closes the vlc player

You can copy the above code into a txt file and change the suffix of that file to .ps1

Automatically call the code whenever a user logs in

Now you want to have this script running whenever a user logs in. Windows offers a task scheduler for these cases. On specific trigger scenarios you can define a task to be executed, which in this case would be our script.

To create a new trigger go under windows search and search for Task Scheduler > Action > Create Task and do the following:

  • Chose a suitable name
  • go to Triggers > New …
    • change Begin the task: to At log on
    • mark Specific user and chose the user
    • OK
  • go to Actions > New …
    • Program/script: you should input the path to your powershell.exe. Mine is under C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. You can also determine this by calling $PsHome in a Powershell. We have to explicitly call powershell and pass our script as argument, because the task scheduler might not know how to open our script and might do that with a text editor, resulting in not executing it.
    • Add arguments(optional) : path to your newly created powershell script
    • OK
  • you can leave the remaining settings as is and klick OK
  • the trigger can be tested by going to Task Scheduler Library in the Task Scheduler Window and right click the newly created trigger > Run

setup of the trigger

Leave a Comment

Your email address will not be published. Required fields are marked *

hungsblog | Nguyen Hung Manh | Dresden
Scroll to Top