Skip to content

Instantly share code, notes, and snippets.

@nonoroazoro
Last active September 1, 2021 02:07
Show Gist options
  • Save nonoroazoro/828f03cf1a06727aa7bce00fcbca0ca2 to your computer and use it in GitHub Desktop.
Save nonoroazoro/828f03cf1a06727aa7bce00fcbca0ca2 to your computer and use it in GitHub Desktop.
Add "Open with Sublime Text" to windows explorer context menu of folders and files - windows 7, 10 (auto elevate UAC)
On Error Resume Next
' 1. Change this to your Sublime Text file path.
path = "C:\Program Files\Sublime Text\sublime_text.exe"
' 2. Optional - Change keyboard shortcut here, for example: "F" if you like.
shortcut = "Q"
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 Sublime Text" & chr(34) & " ?", vbYesNoCancel + vbQuestion)
If result = vbYes Then
shell.RegWrite "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\", "Sublime Text(&" & shortcut & ")", "REG_SZ"
shell.RegWrite "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\Icon", path & ",0", "REG_EXPAND_SZ"
shell.RegWrite "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\command\", path & " " & chr(34) & "%1" & chr(34), "REG_SZ"
shell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\", "Sublime Text(&" & shortcut & ")", "REG_SZ"
shell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\Icon", path & ",0", "REG_EXPAND_SZ"
shell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\command\", path & " " & chr(34) & "%1" & chr(34), "REG_SZ"
ElseIf result = vbNo Then
shell.RegDelete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\command\"
shell.RegDelete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\Icon"
shell.RegDelete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\"
shell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\command\"
shell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\Icon"
shell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\"
Else
WScript.Quit
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment