I want to run a small, unobtrusive script in the background, in the form of a .bat file; and would like it to run in desktop 2 in Windows 10.

The bat file is loaded via Task Scheduler at boot. Can I program the desktop preference, within the .bat file itself?

  • If not, how can I run the batch file in desktop 2 automatically?
    – ProDigit
    Sep 13, 2019 at 6:13
  • You will need software to accomplish this task. Windows cannot do this natively. Unfortunately, the only software I can think of right now is paid, so I can't give you a mention. My answer therefor would be: Its not possible.
    – LPChip
    Sep 13, 2019 at 6:35
  • 1
    Possible duplicate of Windows 10: Assigning Application to Specific Desktop
    – user202729
    Sep 13, 2019 at 6:40
  • No duplication. This is a question on how to start up a program in desktop 2 from boot. The other is to start programs at program start to desktop 2. While my program starts at boot, the boot in desktop 2 option is what makes it special. I would suspect something like this is possible in regedit.
    – ProDigit
    Sep 16, 2019 at 23:12
  • If not in Command, or windows itself, is it possible in PowerShell?
    – ProDigit
    Oct 1, 2019 at 0:50

1 Answer 1


In command, create a .bat file with the location of the ps1 file below. There's no way you can start a ps1 file from boot, but you can start a bat file from boot.

Copy the code below, and save it in the ".ps1" file you have within the .bat boot file.

If ran by Powershell, it'll create an extra desktop, and execute notepad on each desktop. Modify the program if you don't want a new desktop every time it runs, remove the 'notepad' locations if you don't want notepad (or your program) to boot in both desktops; and replace the remaining notepad by the program you want to run.

Window location and dimension should be saved on closing, so their relative position should be the same as last time you used them.. (I think) You will also need to download the'virtualDesktop.ps1' file in the same directory, from here: https://gallery.technet.microsoft.com/scriptcenter/Powershell-commands-to-d0e79cc5

. "$PSScriptRoot\VirtualDesktop.ps1"

"Number of virtual desktops: $(Get-DesktopCount)"
Sleep 1

"Create a new desktop:"
$NewDesktop = New-Desktop
$OldDesktop = Get-CurrentDesktop

"Number of virtual desktops: $(Get-DesktopCount)"
"Number of new desktop: $(Get-DesktopIndex($NewDesktop))"

Sleep 1

"Switch to new desktop, start notepad there and switch back"

Sleep 1

$NewDesktop | Switch-Desktop
Sleep 1
Switch-Desktop $OldDesktop
Sleep 1

"Move notepad to current desktop"
(ps notepad)[0].MainWindowHandle | Move-Window (Get-CurrentDesktop) | Out-Null

Sleep 1

"Move powershell window to new desktop and switch to it"
$NewDesktop | Move-Window (Get-ConsoleHandle) | Switch-Desktop

Sleep 1

"Pin notepad window to all desktops"
Pin-Window ((Get-Process "notepad")[0].MainWindowHandle)

Sleep 1

"Remove original desktop"
Remove-Desktop $OldDesktop

"Number of virtual desktops: $(Get-DesktopCount)"

Sleep 1
  • The'virtualDesktop.ps1' file is no longer available on URL you provided. Oct 27, 2022 at 9:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .