I have many videos stored on my harddrive. The ones which are of dvd or lower quality (480p, max size 7GB), I would like to open using vlc. The ones which are HD quality (720p, 1080p, size greater than 7GB), I'd like to open using PowerDVD.

All files have the same extension (.mkv). Is it possible to program file association in Windows, such that it first looks at the file type (mkv in this case), and then also at the file size. It should automatically use either vlc or PowerDVD for mkv files, based on its size.

Please let me know if such a tweak is possible.


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:

  1. Open regedit, navigate to HKEY_CLASSES_ROOT\.mkv and note the (Default) value. This is the ProgID. Let's assume it's mkvfile.

  2. Navigate to HKEY_CLASSES_ROOT\mkvfile\shell\open\command and modify the (Default) value to something like "D:\MKVSizeCheck.bat" "%1".

  3. 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:

  1. Same as above.

  2. Navigate to HKEY_CLASSES_ROOT\mkvfile\shell\open\command and modify the (Default) value to something like wscript //B "D:\MKVSizeCheck.vbs" "%1".

  3. 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
        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.

  • Hi Karan, Thanks for the prompt response. However, it's not working. Well actually the batch file method does work. However, Windows batch file math seems to be limited to 32-bit precision, so I cannot compare the file size with a number like "4*1024*1024*1024" (4GB). So I tried the vbscript method. I changed the registry entry to MKVSizeCheck.vbs "%1" But when I try to open an mkv file, it gives the error saying "nnn.mkv" is not a valid Win32 application. It doesn't seem to invoke the script file. I tried it with an empty script file too, but it gives the same error. – Sujay Phadke May 30 '15 at 21:12
  • Please see the edit above (step 2 of VBScript section). – Karan May 30 '15 at 21:23
  • Could you explain the meaning of all the double quotation marks? Why are 3 quotes required before the program name, 3 before the first ampersand after the second ampersand? – Sujay Phadke May 30 '15 at 22:25
  • Ok, answering my own Q here (Karan, correct me if I'm wrong). The multi-double quoted strings reduce to something like this when parsed: "C:\Program Files\VLC\VLC.exe objArgs.Item(0) ", 3, false. It's explained here: stackoverflow.com/questions/2942554/… – Sujay Phadke May 31 '15 at 0:04
  • Yes, you got it right. VBScript requires two double quotes if you actually want to include a double quote as part of a quoted string. Thus the first argument to Run actually becomes "C:\Program Files\VLC\VLC.exe" "<mkv file name including path>". You can check this easily by using a MsgBox to print that entire first argument. If you want to know about the other two arguments for Run (i.e. 3 and false), see here. – Karan May 31 '15 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.