Last active
November 1, 2023 21:25
-
-
Save nonoroazoro/b11053eacc773c49e2e675c9ed606c7b to your computer and use it in GitHub Desktop.
Add "Open with VSCode" to windows explorer context menu of folders and files - windows 7, 10 (auto elevate UAC)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Error Resume Next | |
' 1. Change this to your Visual Studio Code file path. | |
path = "D:\Program Files\VSCode\Code.exe" | |
' 2. Optional - Change keyboard shortcut here, for example: "F" if you like. | |
shortcut = "F" | |
Sub ElevateUAC | |
If Not WScript.Arguments.Named.Exists("elevated") Then | |
With CreateObject("Shell.Application") | |
.ShellExecute "wscript.exe", """" & _ | |
WScript.ScriptFullName & """ /elevated", "", "runas", 1 | |
WScript.Quit | |
End With | |
End If | |
End Sub | |
Call ElevateUAC | |
Set shell = CreateoBject("WScript.shell") | |
result = shell.Popup("Yes - Install" & vbCrLf & "No - Uninstall", 0, "Add " & chr(34) & "Open with VSCode" & chr(34) & " ?", vbYesNoCancel + vbQuestion) | |
If result = vbYes Then | |
shell.RegWrite "HKEY_CLASSES_ROOT\*\shell\Open with VSCode\", "VSCode(&" & shortcut & ")", "REG_SZ" | |
shell.RegWrite "HKEY_CLASSES_ROOT\*\shell\Open with VSCode\Icon", path & ",0", "REG_EXPAND_SZ" | |
shell.RegWrite "HKEY_CLASSES_ROOT\*\shell\Open with VSCode\command\", path & " " & chr(34) & "%1" & chr(34), "REG_SZ" | |
shell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\Open with VSCode\", "VSCode(&" & shortcut & ")", "REG_SZ" | |
shell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\Open with VSCode\Icon", path & ",0", "REG_EXPAND_SZ" | |
shell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\Open with VSCode\command\", path & " " & chr(34) & "%1" & chr(34), "REG_SZ" | |
ElseIf result = vbNo Then | |
shell.RegDelete "HKEY_CLASSES_ROOT\*\shell\Open with VSCode\command\" | |
shell.RegDelete "HKEY_CLASSES_ROOT\*\shell\Open with VSCode\Icon" | |
shell.RegDelete "HKEY_CLASSES_ROOT\*\shell\Open with VSCode\" | |
shell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\Open with VSCode\command\" | |
shell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\Open with VSCode\Icon" | |
shell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\Open with VSCode\" | |
Else | |
WScript.Quit | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment