Search code examples
visual-studio-codebatch-file

Have a bat file install Visual Studio Code and add VS Code to file explorer context menu


I currently have a bat file which install vs code when ran. However, one thing that it does not do, is add vs code to the context menu of files and directories. In editing my bat file to add support for that, it doesn't appear to be working. I've done so, by adding editorcontextmenu & explorercontextmenu to the /mergetasks argument. The rest of the parameters in that args call do work. So I feel I am just missing the correct terminology.

Any ideas?

Code below:


@echo off
:: Define the path to the VS Code installer
set VSCodeInstaller=VSCodeSetup-x64-1.XX.X.exe

:: Download the installer if it's not already present
if not exist "%VSCodeInstaller%" (
    echo Visual Studio Code installer not found, downloading it now...
    powershell -Command "Invoke-WebRequest -Uri https://update.code.visualstudio.com/latest/win32-x64-user/stable -OutFile %VSCodeInstaller%"
)

:: Run the VS Code installer with the necessary arguments
echo Installing Visual Studio Code...

start /wait %VSCodeInstaller% /silent /mergetasks="!runcode,addtopath,desktopicon,editorcontextmenu,explorercontextmenu"

:: Optionally clean up installer after installation
del %VSCodeInstaller%

echo Installation complete!

:: Restart the system
echo Restarting the system to complete installation...
shutdown /r /f /t 5

exit

Solution

  • As per Hans' comment above, I was able to update the script with the appropriate flags.

    /mergetasks=!runcode,addcontextmenufiles,addcontextmenufolders,associatewithfiles,addtopath