You are here

file associations with vbscript

1 post / 0 new
trufo
trufo's picture
Offline
Last seen: 2 years 6 months ago
Joined: 2015-06-11 05:08
file associations with vbscript

Hi there,
thought I'd make a small contribution...
Using portable apps for a while now as my main apps. That means there's a the strict minimum installed on my c: partition to keep the system clean.
What had been bugging me was that the file association was not integrated in the system. I tried coffee and some others but I prefer a more direct approach, since all my portableApps are permanently on my d: partition. So here's a (little) vbscript to do just that. Tested on win7x64. Edit at your convenience, save in a text file with vbs extension and double-clic.
If you get an error running it, you might wanna download "windows repair" from tweaking.com and go to the repairs tab clic openRepairs, just tick the "reset registry permissions" and start repair.
Before you try it on win7x86, win8 or whatever, make sure you backup the "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts" registry key in your system.

So here it is :

Option Explicit
Dim objShell
set objShell = WScript.CreateObject ("WScript.Shell")

'Change these lines if needed==================================
addPortableApp "chromePortable", "D:\portableApps\chromePortable\chromePortable.exe"
addPortableApp "foobar2000", "D:\portableApps\foobar2000\foobar2000.exe"
addPortableApp "IrfanViewPortable", "D:\portableApps\IrfanViewPortable\IrfanViewPortable.exe"
addPortableApp "mpc-hcportable", "D:\portableApps\mpc-hcportable\mpc-hcportable.exe"
addPortableApp "Notepad++Portable", "D:\portableApps\Notepad++Portable\Notepad++Portable.exe"
addPortableApp "LibreOfficeWriterPortable", "D:\portableApps\LibreOfficePortable\LibreOfficeWriterPortable.exe"
addPortableApp "LibreOfficeCalcPortable", "D:\portableApps\LibreOfficePortable\LibreOfficeCalcPortable.exe"
addPortableApp "LibreOfficeImpressPortable", "D:\portableApps\LibreOfficePortable\LibreOfficeImpressPortable.exe"
addPortableApp "SumatraPDFportable", "D:\portableApps\sumatraPDF-portable\sumatraPDFportable.exe"
addPortableApp "utorrent", "D:\portableApps\uTorrent221-portable\utorrent.exe"
addFileAssociation ".htm", "chromePortable.exe"
addFileAssociation ".html", "chromePortable.exe"
addFileAssociation ".mht", "chromePortable.exe"
addFileAssociation ".mhtml", "chromePortable.exe"
addFileAssociation ".swf", "chromePortable.exe"
addFileAssociation ".8svx", "foobar2000.exe"
addFileAssociation ".aac", "foobar2000.exe"
addFileAssociation ".afc", "foobar2000.exe"
addFileAssociation ".aif", "foobar2000.exe"
addFileAssociation ".aifc", "foobar2000.exe"
addFileAssociation ".aiff", "foobar2000.exe"
addFileAssociation ".asx", "foobar2000.exe"
addFileAssociation ".au", "foobar2000.exe"
addFileAssociation ".bwf", "foobar2000.exe"
addFileAssociation ".cda", "foobar2000.exe"
addFileAssociation ".cue", "foobar2000.exe"
addFileAssociation ".flac", "foobar2000.exe"
addFileAssociation ".fpl", "foobar2000.exe"
addFileAssociation ".m3u", "foobar2000.exe"
addFileAssociation ".m3u8", "foobar2000.exe"
addFileAssociation ".m4a", "foobar2000.exe"
addFileAssociation ".m4b", "foobar2000.exe"
addFileAssociation ".m4r", "foobar2000.exe"
addFileAssociation ".mka", "foobar2000.exe"
addFileAssociation ".mp+", "foobar2000.exe"
addFileAssociation ".mp1", "foobar2000.exe"
addFileAssociation ".mp2", "foobar2000.exe"
addFileAssociation ".mp3", "foobar2000.exe"
addFileAssociation ".mpc", "foobar2000.exe"
addFileAssociation ".mpp", "foobar2000.exe"
addFileAssociation ".oga", "foobar2000.exe"
addFileAssociation ".ogg", "foobar2000.exe"
addFileAssociation ".ogx", "foobar2000.exe"
addFileAssociation ".opus", "foobar2000.exe"
addFileAssociation ".pls", "foobar2000.exe"
addFileAssociation ".rf64", "foobar2000.exe"
addFileAssociation ".snd", "foobar2000.exe"
addFileAssociation ".spx", "foobar2000.exe"
addFileAssociation ".svx", "foobar2000.exe"
addFileAssociation ".w64", "foobar2000.exe"
addFileAssociation ".wav", "foobar2000.exe"
addFileAssociation ".wave", "foobar2000.exe"
addFileAssociation ".wax", "foobar2000.exe"
addFileAssociation ".wma", "foobar2000.exe"
addFileAssociation ".wv", "foobar2000.exe"
addFileAssociation ".wvx", "foobar2000.exe"
addFileAssociation ".ac3", "foobar2000.exe"
addFileAssociation ".dts", "foobar2000.exe"
addFileAssociation ".ape", "foobar2000.exe"
addFileAssociation ".ani", "IrfanViewPortable.exe"
addFileAssociation ".b3d", "IrfanViewPortable.exe"
addFileAssociation ".bmp", "IrfanViewPortable.exe"
addFileAssociation ".dib", "IrfanViewPortable.exe"
addFileAssociation ".cam", "IrfanViewPortable.exe"
addFileAssociation ".clp", "IrfanViewPortable.exe"
addFileAssociation ".crw", "IrfanViewPortable.exe"
addFileAssociation ".cr2", "IrfanViewPortable.exe"
addFileAssociation ".cur", "IrfanViewPortable.exe"
addFileAssociation ".dcm", "IrfanViewPortable.exe"
addFileAssociation ".acr", "IrfanViewPortable.exe"
addFileAssociation ".ima", "IrfanViewPortable.exe"
addFileAssociation ".dcx", "IrfanViewPortable.exe"
addFileAssociation ".dds", "IrfanViewPortable.exe"
addFileAssociation ".djvu", "IrfanViewPortable.exe"
addFileAssociation ".iw44", "IrfanViewPortable.exe"
addFileAssociation ".dxf", "IrfanViewPortable.exe"
addFileAssociation ".ecw", "IrfanViewPortable.exe"
addFileAssociation ".emf", "IrfanViewPortable.exe"
addFileAssociation ".eps", "IrfanViewPortable.exe"
addFileAssociation ".ps", "IrfanViewPortable.exe"
addFileAssociation ".exr", "IrfanViewPortable.exe"
addFileAssociation ".fpx", "IrfanViewPortable.exe"
addFileAssociation ".g3", "IrfanViewPortable.exe"
addFileAssociation ".gif", "IrfanViewPortable.exe"
addFileAssociation ".hdp", "IrfanViewPortable.exe"
addFileAssociation ".jxr", "IrfanViewPortable.exe"
addFileAssociation ".wdp", "IrfanViewPortable.exe"
addFileAssociation ".icl", "IrfanViewPortable.exe"
addFileAssociation ".ico", "IrfanViewPortable.exe"
addFileAssociation ".iff", "IrfanViewPortable.exe"
addFileAssociation ".lbm", "IrfanViewPortable.exe"
addFileAssociation ".img", "IrfanViewPortable.exe"
addFileAssociation ".jls", "IrfanViewPortable.exe"
addFileAssociation ".jp2", "IrfanViewPortable.exe"
addFileAssociation ".jpc", "IrfanViewPortable.exe"
addFileAssociation ".j2k", "IrfanViewPortable.exe"
addFileAssociation ".jpf", "IrfanViewPortable.exe"
addFileAssociation ".jpg", "IrfanViewPortable.exe"
addFileAssociation ".jpeg", "IrfanViewPortable.exe"
addFileAssociation ".jpe", "IrfanViewPortable.exe"
addFileAssociation ".jpm", "IrfanViewPortable.exe"
addFileAssociation ".kdc", "IrfanViewPortable.exe"
addFileAssociation ".mng", "IrfanViewPortable.exe"
addFileAssociation ".jng", "IrfanViewPortable.exe"
addFileAssociation ".pbm", "IrfanViewPortable.exe"
addFileAssociation ".pcd", "IrfanViewPortable.exe"
addFileAssociation ".pcx", "IrfanViewPortable.exe"
addFileAssociation ".pgm", "IrfanViewPortable.exe"
addFileAssociation ".png", "IrfanViewPortable.exe"
addFileAssociation ".ppm", "IrfanViewPortable.exe"
addFileAssociation ".psd", "IrfanViewPortable.exe"
addFileAssociation ".psp", "IrfanViewPortable.exe"
addFileAssociation ".ras", "IrfanViewPortable.exe"
addFileAssociation ".sun", "IrfanViewPortable.exe"
addFileAssociation ".raw", "IrfanViewPortable.exe"
addFileAssociation ".rle", "IrfanViewPortable.exe"
addFileAssociation ".sff", "IrfanViewPortable.exe"
addFileAssociation ".sfw", "IrfanViewPortable.exe"
addFileAssociation ".sgi", "IrfanViewPortable.exe"
addFileAssociation ".rgb", "IrfanViewPortable.exe"
addFileAssociation ".sid", "IrfanViewPortable.exe"
addFileAssociation ".tga", "IrfanViewPortable.exe"
addFileAssociation ".tif", "IrfanViewPortable.exe"
addFileAssociation ".tiff", "IrfanViewPortable.exe"
addFileAssociation ".wbmp", "IrfanViewPortable.exe"
addFileAssociation ".webp", "IrfanViewPortable.exe"
addFileAssociation ".wmf", "IrfanViewPortable.exe"
addFileAssociation ".xbm", "IrfanViewPortable.exe"
addFileAssociation ".xpm", "IrfanViewPortable.exe"
addFileAssociation ".avi", "mpc-hcportable.exe"
addFileAssociation ".mpeg", "mpc-hcportable.exe"
addFileAssociation ".mpg", "mpc-hcportable.exe"
addFileAssociation ".mpe", "mpc-hcportable.exe"
addFileAssociation ".m1v", "mpc-hcportable.exe"
addFileAssociation ".m2v", "mpc-hcportable.exe"
addFileAssociation ".mpv2", "mpc-hcportable.exe"
addFileAssociation ".mp2v", "mpc-hcportable.exe"
addFileAssociation ".pva", "mpc-hcportable.exe"
addFileAssociation ".evo", "mpc-hcportable.exe"
addFileAssociation ".m2p", "mpc-hcportable.exe"
addFileAssociation ".ts", "mpc-hcportable.exe"
addFileAssociation ".tp", "mpc-hcportable.exe"
addFileAssociation ".trp", "mpc-hcportable.exe"
addFileAssociation ".m2t", "mpc-hcportable.exe"
addFileAssociation ".m2ts", "mpc-hcportable.exe"
addFileAssociation ".mts", "mpc-hcportable.exe"
addFileAssociation ".rec", "mpc-hcportable.exe"
addFileAssociation ".vob", "mpc-hcportable.exe"
addFileAssociation ".ifo", "mpc-hcportable.exe"
addFileAssociation ".mkv", "mpc-hcportable.exe"
addFileAssociation ".webm", "mpc-hcportable.exe"
addFileAssociation ".mp4", "mpc-hcportable.exe"
addFileAssociation ".m4v", "mpc-hcportable.exe"
addFileAssociation ".mp4v", "mpc-hcportable.exe"
addFileAssociation ".mpv4", "mpc-hcportable.exe"
addFileAssociation ".hdmov", "mpc-hcportable.exe"
addFileAssociation ".mov", "mpc-hcportable.exe"
addFileAssociation ".3gp", "mpc-hcportable.exe"
addFileAssociation ".3gpp", "mpc-hcportable.exe"
addFileAssociation ".3ga", "mpc-hcportable.exe"
addFileAssociation ".3g2", "mpc-hcportable.exe"
addFileAssociation ".3gp2", "mpc-hcportable.exe"
addFileAssociation ".flv", "mpc-hcportable.exe"
addFileAssociation ".f4v", "mpc-hcportable.exe"
addFileAssociation ".ogm", "mpc-hcportable.exe"
addFileAssociation ".ogv", "mpc-hcportable.exe"
addFileAssociation ".rm", "mpc-hcportable.exe"
addFileAssociation ".ram", "mpc-hcportable.exe"
addFileAssociation ".rpm", "mpc-hcportable.exe"
addFileAssociation ".rmm", "mpc-hcportable.exe"
addFileAssociation ".rt", "mpc-hcportable.exe"
addFileAssociation ".rp", "mpc-hcportable.exe"
addFileAssociation ".smi", "mpc-hcportable.exe"
addFileAssociation ".smil", "mpc-hcportable.exe"
addFileAssociation ".wmv", "mpc-hcportable.exe"
addFileAssociation ".wmp", "mpc-hcportable.exe"
addFileAssociation ".wm", "mpc-hcportable.exe"
addFileAssociation ".asf", "mpc-hcportable.exe"
addFileAssociation ".smk", "mpc-hcportable.exe"
addFileAssociation ".bik", "mpc-hcportable.exe"
addFileAssociation ".fli", "mpc-hcportable.exe"
addFileAssociation ".flc", "mpc-hcportable.exe"
addFileAssociation ".flic", "mpc-hcportable.exe"
addFileAssociation ".dsm", "mpc-hcportable.exe"
addFileAssociation ".dsv", "mpc-hcportable.exe"
addFileAssociation ".dsa", "mpc-hcportable.exe"
addFileAssociation ".dss", "mpc-hcportable.exe"
addFileAssociation ".ivf", "mpc-hcportable.exe"
addFileAssociation ".divx", "mpc-hcportable.exe"
addFileAssociation ".rmvb", "mpc-hcportable.exe"
addFileAssociation ".amv", "mpc-hcportable.exe"
addFileAssociation ".txt", "Notepad++Portable.exe"
addFileAssociation ".log", "Notepad++Portable.exe"
addFileAssociation ".ini", "Notepad++Portable.exe"
addFileAssociation ".php", "Notepad++Portable.exe"
addFileAssociation ".js", "Notepad++Portable.exe"
addFileAssociation ".asp", "Notepad++Portable.exe"
addFileAssociation ".css", "Notepad++Portable.exe"
addFileAssociation ".xml", "Notepad++Portable.exe"
addFileAssociation ".nfo", "Notepad++Portable.exe"
addFileAssociation ".srt", "Notepad++Portable.exe"
addFileAssociation ".doc", "LibreOfficeWriterPortable.exe"
addFileAssociation ".docx", "LibreOfficeWriterPortable.exe"
addFileAssociation ".docm", "LibreOfficeWriterPortable.exe"
addFileAssociation ".dot", "LibreOfficeWriterPortable.exe"
addFileAssociation ".dotx", "LibreOfficeWriterPortable.exe"
addFileAssociation ".dotm", "LibreOfficeWriterPortable.exe"
addFileAssociation ".odt", "LibreOfficeWriterPortable.exe"
addFileAssociation ".xls", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlsx", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xl", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlsm", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlsb", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlam", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xltx", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xltm", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xla", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlt", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlk", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlm", "LibreOfficeCalcPortable.exe"
addFileAssociation ".xlw", "LibreOfficeCalcPortable.exe"
addFileAssociation ".prn", "LibreOfficeCalcPortable.exe"
addFileAssociation ".csv", "LibreOfficeCalcPortable.exe"
addFileAssociation ".odc", "LibreOfficeCalcPortable.exe"
addFileAssociation ".ods", "LibreOfficeCalcPortable.exe"
addFileAssociation ".udl", "LibreOfficeCalcPortable.exe"
addFileAssociation ".dsn", "LibreOfficeCalcPortable.exe"
addFileAssociation ".mdb", "LibreOfficeCalcPortable.exe"
addFileAssociation ".mde", "LibreOfficeCalcPortable.exe"
addFileAssociation ".accdb", "LibreOfficeCalcPortable.exe"
addFileAssociation ".accde", "LibreOfficeCalcPortable.exe"
addFileAssociation ".dbc", "LibreOfficeCalcPortable.exe"
addFileAssociation ".dbf", "LibreOfficeCalcPortable.exe"
addFileAssociation ".iqy", "LibreOfficeCalcPortable.exe"
addFileAssociation ".dqy", "LibreOfficeCalcPortable.exe"
addFileAssociation ".rqy", "LibreOfficeCalcPortable.exe"
addFileAssociation ".oqy", "LibreOfficeCalcPortable.exe"
addFileAssociation ".cub", "LibreOfficeCalcPortable.exe"
addFileAssociation ".uxdc", "LibreOfficeCalcPortable.exe"
addFileAssociation ".csv", "LibreOfficeCalcPortable.exe"
addFileAssociation ".slk", "LibreOfficeCalcPortable.exe"
addFileAssociation ".dif", "LibreOfficeCalcPortable.exe"
addFileAssociation ".ppt", "LibreOfficeImpressPortable.exe"
addFileAssociation ".pptx", "LibreOfficeImpressPortable.exe"
addFileAssociation ".pptm", "LibreOfficeImpressPortable.exe"
addFileAssociation ".ppsx", "LibreOfficeImpressPortable.exe"
addFileAssociation ".pps", "LibreOfficeImpressPortable.exe"
addFileAssociation ".ppsm", "LibreOfficeImpressPortable.exe"
addFileAssociation ".pot", "LibreOfficeImpressPortable.exe"
addFileAssociation ".potx", "LibreOfficeImpressPortable.exe"
addFileAssociation ".potm", "LibreOfficeImpressPortable.exe"
addFileAssociation ".odp", "LibreOfficeImpressPortable.exe"
addFileAssociation ".pdf", "sumatraPDF.exe"
addFileAssociation ".torrent", "utorrent.exe"
'=================================================

Sub addPortableApp( name, path )
objShell.RegWrite "HKCU\Software\Classes\Applications\" & name & ".exe\shell\open\command\", chr(34) & path & chr(34) & " " & chr(34) & "%1" & chr(34)
objShell.RegWrite "HKCU\Applications\" & name & ".exe\shell\open\command\", chr(34) & path & chr(34) & " " & chr(34) & "%1" & chr(34)
End Sub

Sub addFileAssociation( fileExt, whichApp )
If ( Left(fileExt, 1) "." ) Then
fileExt = "." & fileExt
End If
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\OpenWithList\a", whichApp
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\OpenWithList\MRUList", "a"
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\UserChoice\Progid", whichApp
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\UserChoice\Progid", "Applications\" & whichApp
End Sub