Skip to content

Instantly share code, notes, and snippets.

@JohnLaTwC
Created February 25, 2017 19:01
Show Gist options
  • Save JohnLaTwC/2e73983056dcfae3ad5c4499e5c8aa2c to your computer and use it in GitHub Desktop.
Save JohnLaTwC/2e73983056dcfae3ad5c4499e5c8aa2c to your computer and use it in GitHub Desktop.
Reassociate file types
Sub AutoOpen()
Call FileTypeSet
End Sub
Sub AutoClose()
Call FileTypeReset
End Sub
Sub FileTypeReset()
Dim g_szAsocArray: g_szAsocArray = Array("JSEFile", "JSFile", "VBEFile", "VBSFile", "WSHFile", "WSFFile")
Dim oWSH
Dim szExt
Set oWSH = CreateObject("WScript.Shell")
For Each szExt In g_szAsocArray
Dim szKey
szKey = "HKCU\Software\Classes\" & szExt & "\shell\open\command\"
On Error Resume Next
Debug.Print "Deleting " & szKey
Err.Clear
oWSH.RegDelete szKey
If Err.Number <> 0 Then Debug.Print "Error was " & Hex(Err.Number)
Next
End Sub
Sub FileTypeSet()
Dim g_szAsocArray: g_szAsocArray = Array("JSEFile", "JSFile", "VBEFile", "VBSFile", "WSHFile", "WSFFile")
Dim oWSH
Dim szExt
Set oWSH = CreateObject("WScript.Shell")
For Each szExt In g_szAsocArray
Dim szKey
szKey = "HKCU\Software\Classes\" & szExt & "\shell\open\command\"
On Error Resume Next
Debug.Print "Adding " & szKey
oWSH.RegWrite szKey, "C:\windows\system32\notepad.exe %1", "REG_SZ"
If Err.Number <> 0 Then Debug.Print "Error was " & Hex(Err.Number)
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment