Windows 7 Scripting: assoc and ftype

freex

New Member
Joined
Aug 18, 2009
Hello,
I've made script to associate video files with MPlayer (not WMP). It's simple .bat file, here's part of it:
Code:
ftype MPlayer.Video=\"%~dp0mplayer.exe\" \"%%1\" \"%%*\" 1>nul

assoc .avi=MPlayer.Video 1>nul
assoc .mkv=MPlayer.Video 1>nul
assoc .flv=MPlayer.Video 1>nul
assoc .wmv=MPlayer.Video 1>nul

It's working, here's the result:
Code:
C:\>ftype MPlayer.Video
MPlayer.Video=\"C:\Program Files (x86)\MPlayer\mplayer.exe\" \"%1\" \"%*\"

C:\>assoc .flv
.flv=MPlayer.Video

Problem is that Windows Explorer completely ignores it. See screenshots:
Link Removed due to 404 Error
Link Removed due to 404 Error

File type is set properly, but action is "Windows Shell Common Dll". Even if I click to Change, there's nothing like MPlayer :(
 
A much easier way would be through the registry or download FileTypesMan

Very simple and easy to use.

If you need help with a registry script, just let me know.
 
I used assoc and ftype commands because its easy to back up associations and maybe someday restore. And script file because it's like "write once and use many times". FileTypesMan doesn't provide backup neither scripting.
If you know a way to do it, I would appreciate your help.
 
I'm assuming these are command-line utilities and are not included in Windows 7.,

Therefore I'm sure you're using the correct syntax, but they probably will not work under Windows 7.
 
No, its part of Windows. Either Windows 7. I've sent you web page that I'm learning syntax from.
Run command line and type:
Code:
assoc /?
ftype /?
 
Yes, I see what you mean, nice discovery.

First off, ftype does not say that it will create a filetype, just change or modify, so if you don't have MPlayer.Video in the registry, I doubt it will work

If you had the MPlayer.Video key, I'm no command line expert, but see if this might work:

assoc .avi=MPlayer.Video,avi 1>nul
assoc .mkv=MPlayer.Video.mkv 1>nul
assoc .flv=MPlayer.Video.flv 1>nul
assoc .wmv=MPlayer.Video.wmv 1>nul

Also the .mkv file extension has a Content Type........video/x-matroska and a Perceived type...........video which your script does not include. Same with the .wmv file type.

Isn't there an easier way such as going to Default Programs, selecting Windows media Player and uncheck those file types.

Now right-click on one of those extensions and you should have an Open With entry on the right-click context menu where you can select Mplayer from the list and check the box to set it as Default.
 
You are right. I've misjudged those two commands. I thought it's Windows 7 problem, but it's not working on Windows XP neither.
 
No, it's working !!!!

Problem was one stupid dot in Mplayer.Video.

Here is the entire script in case someone googles this (script must be in same directory like mplayer.exe):
Code:
@echo off
echo Mplayer file association script&echo.
echo   Please make sure you have administrative rights.

set assocfile=%userprofile%\.mplayer-assoc

echo.
echo [1] Associate video files with MPlayer
echo [2] Restore saved associations
echo [3] Remove saved associations
echo.
set /p sel=
if [%sel%] equ [1] goto assoclabel
if [%sel%] equ [2] goto restorelabel
if [%sel%] equ [3] goto removelabel
goto exitlabel


:assoclabel
echo.
if exist "%assocfile%" echo - Saved associations already exist&goto exitlabel

echo - Saving to backup file %assocfile%

1>>"%assocfile%" 2>nul assoc .avi
1>>"%assocfile%" 2>nul assoc .mkv
1>>"%assocfile%" 2>nul assoc .flv
1>>"%assocfile%" 2>nul assoc .wmv

echo - Associating with MPlayer

1>nul assoc .avi=MPlayerVideoFile
1>nul assoc .mkv=MPlayerVideoFile
1>nul assoc .flv=MPlayerVideoFile
1>nul assoc .wmv=MPlayerVideoFile
1>nul ftype MPlayerVideoFile="%~dp0mplayer.exe" "%%1"

echo - Finished
goto exitlabel


:restorelabel
echo.
if not exist "%assocfile%" echo - Saved associations not found&goto exitlabel

echo - Cleaning associations

1>nul 2>nul assoc .avi=
1>nul 2>nul assoc .mkv=
1>nul 2>nul assoc .flv=
1>nul 2>nul assoc .wmv=
1>nul 2>nul ftype MPlayerVideoFile=

echo - Restoring saved associations from file %assocfile%

for /f "usebackq tokens=*" %%g in ("%assocfile%") do 1>nul assoc %%g

echo - Finished
goto exitlabel


:removelabel
echo.&echo - Removing file %assocfile%
del "%assocfile%"

echo - Finished
goto exitlabel


:exitlabel
echo.&pause&exit /b
 
Back
Top Bottom