Scripting: assoc and ftype

Discussion in 'Windows 7 Help and Support' started by freex, Aug 18, 2009.

  1. freex

    freex New Member

    Joined:
    Aug 18, 2009
    Messages:
    12
    Likes Received:
    4
    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:
    [​IMG]
    [​IMG]

    File type is set properly, but action is "Windows Shell Common Dll". Even if I click to Change, there's nothing like MPlayer :(
     
    Mike and (deleted member) like this.
  2. reghakr

    reghakr Excellent Member

    Joined:
    Jan 26, 2009
    Messages:
    14,220
    Likes Received:
    180
    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.
     
  3. freex

    freex New Member

    Joined:
    Aug 18, 2009
    Messages:
    12
    Likes Received:
    4
    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.
     
  4. reghakr

    reghakr Excellent Member

    Joined:
    Jan 26, 2009
    Messages:
    14,220
    Likes Received:
    180
    Where exactly do you find the ftype and accoss commands?
     
  5. freex

    freex New Member

    Joined:
    Aug 18, 2009
    Messages:
    12
    Likes Received:
    4
  6. reghakr

    reghakr Excellent Member

    Joined:
    Jan 26, 2009
    Messages:
    14,220
    Likes Received:
    180
    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.
     
  7. freex

    freex New Member

    Joined:
    Aug 18, 2009
    Messages:
    12
    Likes Received:
    4
    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 /?
    
     
  8. reghakr

    reghakr Excellent Member

    Joined:
    Jan 26, 2009
    Messages:
    14,220
    Likes Received:
    180
    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.
     
  9. freex

    freex New Member

    Joined:
    Aug 18, 2009
    Messages:
    12
    Likes Received:
    4
    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.
     
  10. freex

    freex New Member

    Joined:
    Aug 18, 2009
    Messages:
    12
    Likes Received:
    4
    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
    
     
    reghakr and (deleted member) like this.
  11. reghakr

    reghakr Excellent Member

    Joined:
    Jan 26, 2009
    Messages:
    14,220
    Likes Received:
    180
    Excellent,

    NICE WORK!!!!!!
     

Share This Page

Loading...