Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio code cmd error: Cannot be loaded because running scripts is disabled on this system

People also ask

How do I enable running scripts on my system?

* Note: If you still receive the error "Scripts are disabled on this system", give one of the following commands and try again to run your script: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned. set-executionpolicy remotesigned.


I found out here that you can add to your visual studio code settings the following and the problem will vanish: For visual studio code settings, go to File -> Preferences -> Settings -> Extensions -> Scroll down and find "Edit in settings.json". Do not forget to restart the visual studio code

"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]

The reason is that, in build command line integrations like visual studio code, you need to set the command line policies by your self. By setting the above configurations, the visual studio code will do that for you.

(read this to understand better the command line policies)

Update August 2021

It seems that terminal.integrated.shellArgs is deprecated. This answer shows how to do it in new versions.


For more simplicity, I want to add the vs code settings path in addition to Ricardo's answer. you can get it like this:

File -> Preferences -> Settings and in the search bar write "automation".

After that, by looking your operating system enter "edit in settings.json".

Finally, add the following b/n the braces:

"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]

enter image description here


The simplest way to deal with this problem from Visual Studio Code is to change from powerShell to cmd (assuming there's no reason for using powershell in your case). To do so, follow these few steps:

  1. Terminal -> New Terminal
  2. In right lower corner select "Select Default Shell" option

enter image description here

  1. Select "Command prompt"

enter image description here

I have not found such solution among current answers. Hope that helps!


the issue is that PowerShell by default restricts running scripts unless we change the execution policies.

we can change the execution policies by adding -ExecutionPolicy Bypass args. in vscode you will have to create a shell profile with these args by adding below in settings.json (ctrl + shift + p and type "settings.json")

"terminal.integrated.profiles.windows": {
  "PowerShell": {
    "source": "PowerShell",
    "icon": "terminal-powershell",
    "args": ["-ExecutionPolicy", "Bypass"]
  }
},
"terminal.integrated.defaultProfile.windows": "PowerShell",

Note: terminal.integrated.shellArgs settings have been deprecated.


Face the same issue and this works for me. open PowerShell as Administrator and paste this.

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser  

  1. Open VS code

  2. File -> Prefrences -> settings

  3. in the Search bar -> Search for "terminal.integrated.shellArgs"

  4. Click on the "Edit in setting.json" for Terminal>integrated>ShellArgs > windows [whatever you OS, select the respective settings]

  5. At the top of the json file add this :

    terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]

    For example after adding your json might look like:

{
    "terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"],
    "git.autofetch": true,
    "peacock.favoriteColors": [
        {
            "name": "Angular Red",
            "value": "#b52e31"
        },
        {
            "name": "Auth0 Orange",
            "value": "#eb5424"
        },
  1. restart the VS code and try the command again (in my case i was trying ng serve)

Note: terminal.integrated.shellArgs settings have been deprecated.