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

后端 未结 11 1493
北荒
北荒 2020-12-02 07:52

Inside of visual studio code, I\'m trying to execute a script.bat from the command line, but I\'m getting the following error:

File C:\\Theses_Repo\\t

相关标签:
11条回答
  • 2020-12-02 08:19

    If you don't need to explicitly run this on PowerShell, then you may want to try running it in the command prompt.

    Just type cmd and press enter. Doing so will open the command prompt in the current terminal window. It will behave same as a normal command prompt.

    0 讨论(0)
  • 2020-12-02 08:24
    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)
    0 讨论(0)
  • 2020-12-02 08:25

    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"]
    
    0 讨论(0)
  • 2020-12-02 08:25

    For security reasons, in case you share the computer with other users, use: PowerShell:

    Set-ExecutionPolicy -Scope CurrentUser Unrestricted

    No need for Admin privileges.

    0 讨论(0)
  • 2020-12-02 08:26

    I have faced the same problem due to security reasons on Windows 10. I managed to fix it by running the following command in PowerShell:

    Set-ExecutionPolicy -ExecutionPolicy Unrestricted
    
    0 讨论(0)
  • 2020-12-02 08:32

    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)

    0 讨论(0)
提交回复
热议问题