Execute Powershell from File Explorer after installing VS Code - powershell

VS Code is trying to position itself as a new way to work with Powershell, and one of the changes it makes upon installation is to replace the File Explorer context menu option "Run with PowerShell" on .ps1 files with a new "Open with Code" option instead.
Is there a way to remove the "Open with Code" option and replace it with the old "Run with PowerShell" option? I assume this would involve the registry somehow but I don't know enough about the registry in general to do it safely.

Try this:
Save the following contents into a file "EnablePowerShellRightClickRun.reg", then right click - merge.
Then it doesn't matter which application you associate .ps1 files with - you still have "Run with Powershell" as a right click option.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunPS]
#="Run with Powershell"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunPS\command]
#="\"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe\" -File \"%1\""

VS Code is not really positioning itself as the new way to work with PowerShell, it will be the only "built-in" way with Windows to work with it because the PowerShell ISE is being depreciated.
Either way, VS Code did not cause that option to disappear. I have VS Code and the PS extension on my machine and still have access to both options:
When you install VS Code you are prompted to add the right-click menu options, so if you opt'ed into those then it is not what removed your "Run with PowerShell" option.
If you want to remove those right-click options then you would have to uninstall VS Code and install it again, making sure those options are not checked.
To restore your menu option to Run with PowerShell verify you have not changed the default program for PowerShell files (e.g. ps1). If you set that to VS Code it will cause the option to be removed from your right-click menu. You can restore it by changing the default program in Windows back to Notepad.

Related

PowerShell console in Visual Studio Code: How to copy-paste?

I cannot Copy-Paste from the Visual Studio Code console. In ISE one can copy-paste some of the output, but it does not seem to be possible in Visual Studio Code Terminal. How can I copy-paste the output from the console when running PowerShell commands? I have the PowerShell Extension.
Ctrl+C and Ctrl+V for copying / pasting work as-is in Visual Studio Code's integrated terminal.
By contrast, right-click behavior is configurable:
On Windows, the default behavior is to copy, if text is currently selected, and paste otherwise - as in regular console windows.
To get the same behavior as in the Windows PowerShell ISE, i.e. to instead show a shortcut menu, which contains Copy and Paste commands, add the following line to your settings.json file (before the closing }):
"terminal.integrated.rightClickBehavior": "default",
Alternatively, use the settings GUI (press Ctrl+,):
Note:
The screenshot was taken on macOS, where selectWord is the default setting; on Windows, it is copyPaste, with the behavior as described above.
Also note the GUI's convenient search feature: typing right click in the search field was sufficient to locate the relevant setting.

Permission denied when I try to open VSCode using a command line

I'm trying to edit a file by openning it via git using VS Code as an editor
$code texte.txt
and I got this
/c/Users/MAYA/AppData/Local/Programs/Microsoft VS Code/bin/code: line 61: /c/Users/MAYA/AppData/Local/Programs/Microsoft VS Code/Code.exe: Permission denied
I google it but didn' find anything usefull, any help please?
P.S: my environement: windows 7, MINGW64
Thought it would be useful to share this as well.
WSL is not able to run VS Code with Windows environment administrator permissions.
Right-click on your Visual Studio Code shortcut and select "Properties" in C:\Users\<myUsername>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Visual Studio Code
In the Compatibility tab's settings section un-check "Run this program as an administrator"
A wonderful person brought this up on this Reddit post.
Follow the steps below and be proud of the OS you use.
Search for "Advanced System Setting" from Start.
Click on Environment Variables
On System Variables choose "path" from Variable tab and click on Edit.
Click on New on the right side of the popup window.
Copy your path from the Explorer's breadcrumb path and paste it into the
new opened path in step 4, example:- C:\Program Files\Microsoft VS
Code\bin
Click Ok on all the open windows to confirm changes and restart your cmd
Now you run it $code.cmd file.extension
I added the path from the Explorer's breadcrumb to Environment Variables under Advanced System Setting then I used $code.cmd file.extension

Configure Autohotkey to edit scripts with Notepad++

I have my default editor for .ahk files set to Notepad++ Portable on my work laptop, but selecting Edit This Script opens files in the standard Windows Notepad.
A post on the AHK forums suggests editing the registry, but I don't see any entries under HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command.
How can I configure AutoHotkey to edit scripts with Notepad++?
For whatever reason, the Registry entry doesn't exist by default, but it is recognized by the application once created.
Navigate to HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell in RegEdit.
Right-click the Shell folder, select New > Key and name this Edit.
Right-click the Edit folder, select New > Key and name this Command.
Double click the (Default) string entry in Command.
Paste in "C:\Program Files\Notepad++\Notepad++.exe" "%1" to this window.
Reload AutoHotkey for the changes to take effect.
Note: I don't use Notepad++, but this works for VS Code on my system, and will for N++ as long as the directory information for the executable is correct.
The corresponding .reg file looks like this:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command]
#="\"C:\\Program Files\\Notepad++\\notepad++.exe\" \"%1\""
The registry entry in item 5 of the previous answer did not work. I don't even know what the extra %* at the end means, so I simplified it to:
"C:\Program Files\Notepad++\Notepad++.exe" "%1"
For AHK version 2, changing the registry didn't work for me (I tried both Computer\HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command and Computer\HKEY_CLASSES_ROOT\.ahk\Shell\Edit\Command), but this did it for me. It adds two menu items to the AHK tray menu after a divider:
EditWithNotepadPlusPlus(*)
{
Run "C:\Program Files\Notepad++\notepad++.exe " A_ScriptFullPath
}
EditWithVsCode(*)
{
Run "C:\Program Files\Microsoft VS Code\Code.exe " A_ScriptFullPath
}
A_TrayMenu.Add()
A_TrayMenu.Add("Edit with VS Code", EditWithVsCode)
A_TrayMenu.Add("Edit with Notepad++", EditWithNotepadPlusPlus)
return
If you are like me and you are hesitant to modify the registry, there is a way to do this using AutoHotKey code.
This is a method I use to edit the script with a different editor. Although I am using Visual Studio Code, the method is the same no matter which editor you want to use. One caveat though: we can't change the existing "Edit This Script" menu item, since that is considered one of the standard menu items and can't be modified. Instead I am adding a new menu item at the top of the menu that says "Edit With Notepad++".
EditWithNotepadPlusPlus()
{
Run "C:\Program Files (x86)\Notepad++\notepad++.exe" "%A_ScriptFullPath%"
}
; Remove the standard menu items temporarily
Menu, Tray, NoStandard
; Add our custom menu item labeled "Edit With Notepad++"
; and calls the function above
Menu, Tray, Add, Edit With Notepad++, EditWithNotepadPlusPlus
; Add a separator
Menu, Tray, Add
; Put the standard menu items back, under our custom menu item
Menu, Tray, Standard
Note: If you're wondering, the lines Menu, Tray, NoStandard and Menu, Tray, Standard are not required. The reason I use those lines is because by default, Menu, MenuName, Add adds menu items to the bottom of the menu. For aesthetic and practical reasons, I prefer Exit to be the last menu item. So Menu, Tray, NoStandard and Menu, Tray, Standard will cause our menu item to appear at the top.
One added benefit of this method is that if you transfer your scripts to a new computer, it should still work (provided you have Notepad++ installed on the other computer). If you edit the registry, you have to remember to edit the registry again.
Using AHK v1.1.3.02 on Win10 with string
"C:\Program Files\TextPad 8\TextPad.exe" "%1"
worked well.
The registry change mentioned in other answers for me worked, but you may want to further add the following flags:
C:\Program Files (x86)\Notepad++\notepad++.exe %1 -multiInst -nosession
These flags will stop Notepad++ from recognizing this window as part of your overall session, so it won't overwrite your normal session history or anything. I don't remember where I first found these solutions but I'm switching computers atm and found them in my registry and noticed they weren't mentioned anywhere in this thread.
Was not working for me, i fixed it by first using the suggestion by R River
C:\Program Files (x86)\Notepad++\notepad++.exe %1 -multiInst -nosession
But this would create a new session each time, so i tried removing the end parameters and it now works.
C:\Program Files (x86)\Notepad++\notepad++.exe %1
Simplest way I've found is to:
Right click the .ahk file
Select "Open with" -> "Choose another app"
Check "Always use this app to open .ahk files"
Then select NotePad++ from the list
If it's not listed select "More Apps" and scroll down to NotePad++. (Mind you this example is Windows 10 specific, but previous versions are very similar.)
Editing the registry is great, don't get me wrong, but it takes longer. It's kinda like using a truck to swat a fly! Anyways, hope this works for you. I use it all the time to set the file associations I want.

In Visual Studio Code, how do you inject clink into the integrated terminal?

I was using clink with ConEmu for various node related tasks on windows, but now I'm trying Visual Studio code.
How do I inject clink into Visual Studio Code's integrated terminal, so that I can get real command history persistence between sessions, incremental history search, etc.?
With ConEmu I could inject clink by dropping the clink folder into a specified pickup directory.
I've tried using the path to the included clink bat file, and the clink exe in the VS Code setting terminal.integrated.shell.windows but these spawn and then close the command shell immediately.
Thanks!
I discovered that you can pass arguments to the integrated shell in Visual Studio Code. Combined with the cmd.exe /K option which Carries out the command specified by string but remains, clink can be injected.
In VS Code, go to File > Preferences > Settings or use Ctrl , and add the settings:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "C:\\path\\to\\clink\\clink_x64.exe inject"]
This is the equivalent of opening a command prompt in Windows, and running clink_x64 inject.
It is not answer for your question, but there is another trick to see cmder and text editor in one window. You can open your text editor as another tab in cmder, which I described here:
https://medium.com/#WMorkowski/protip-integrating-cmder-with-text-editor-7f08a6e76de7
from article:
Run your cmder.
Go to ‘Settings -> Startup -> Environment’
Type: set EDITOR_PATH=C:\Program Files (x86)\Microsoft VS Code\Code.exe alias editor="%EDITOR_PATH%" $1 -new_console:s50V Where
in the first line you should type path to your text editor (I was
testing it on Visual Studio Code and Sublime, but it should work with
other editors).
Save your settings
Type ‘editor’ command in command line.
Whoa! We almost finished. But in most cases you don’t want console tab
to be attached to the top of the window. You should close console tab,
and open it again, paying attention to check “New console split to
bottom” checkbox and choose the right console type. Now when you
finally set everything up, you should go to ‘Settings -> Startup’, and
check “Auto save/restore opened tabs” checkbox to save our new
workflow. Now every time you run cmder, your tabs setup will be
restored.
Expanding on my comment:
Open settings.json with:
File > Open > %APPDATA%\Code\User\settings.json
And assuming you installed clink with the magic of chocolatey:
choco install clink-maintained
Then your clink_x64.exe lives here:
C:\Program Files (x86)\clink\clink_x64.exe
And the lines you add to settings.json look like:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/K",
"C:\\Program Files (x86)\\clink\\clink_x64.exe",
"inject",
"--profile",
"~\\clink"
],
Note the addition of --profile ... this allows the history to be persistent between vscode sessions.

Accidentally deleted the Git Shell shortcut

So where is it? I checked the usual suspects, namely Program Files and Program Files (x86), but I didn't see any mention of GitHub there.
I know someone offered an answer but deleted it for whatever reason before I could accept it, so here goes.
You need to create a shortcut to a command, which is actually rather convoluted.
Right-click on the desktop and do New > Shortcut
Browse to any file, but make sure it's not a .exe file!!
Click next through the rest of the wizard and accept the defaults
Now right-click the shortcut, go to Properties > Shortcut tab
Set the Target to: "C:\Documents and Settings\\AppData\Local\GitHub\GitHub.appref-ms" --open-shell
In step 5 above, the quotes are required.
A better solution is to run
%LOCALAPPDATA%\GitHub\GitHub.appref-ms --reinstall-shortcuts
which will recreate the shortcut on the desktop.