Windows file association based on file type and then size
Solution 1:
You'll have to associate the MKV extension with a batch file or PowerShell/VB script that in turn performs the file size check and invokes the appropriate application.
Here's how to do it with a batch file:
Open regedit, navigate to
HKEY_CLASSES_ROOT\.mkv
and note the (Default) value. This is the ProgID. Let's assume it's mkvfile.Navigate to
HKEY_CLASSES_ROOT\mkvfile\shell\open\command
and modify the (Default) value to something like"D:\MKVSizeCheck.bat" "%1"
.-
Now create the
D:\MKVSizeCheck.bat
batch file with the following contents:if %~z1 leq 524288000 ( start "" /max "C:\Program Files\VLC\VLC.exe" "%~1" ) else ( start "" /max "C:\Program Files\PowerDVD\PowerDVD.exe" "%~1" )
Here's how to do it with VBScript:
Same as above.
Navigate to
HKEY_CLASSES_ROOT\mkvfile\shell\open\command
and modify the (Default) value to something likewscript //B "D:\MKVSizeCheck.vbs" "%1"
.-
Now create the
D:\MKVSizeCheck.vbs
file with the following contents:set objArgs = WScript.Arguments set objShell = WScript.CreateObject("WScript.Shell") set objFSO = WScript.CreateObject("Scripting.FileSystemObject") if objFSO.GetFile(objArgs.Item(0)).Size <= 524288000 then objShell.Run """C:\Program Files\VLC\VLC.exe"" """ & objArgs.Item(0) & """", 3, false else objShell.Run """C:\Program Files\PowerDVD\PowerDVD.exe"" """ & objArgs.Item(0) & """", 3, false end if
Note #1: Modify the paths as required obviously. Also the code above sets 500MB (= 524288000 bytes) as the threshold so change that too as per your needs (very large values may be possible only in VBScript though).
Note #2: You can always use a utility like FileTypesMan to do steps 1-2 if you're unsure about manually editing the registry.
Note #3: Using a batch file will cause a console window to flash which might be irritating. Now this can be hidden using something like Hidden Start or VBScript, but why bother when it's better to directly use VBScript in the first place.