Jump to content

File associations


erebus
 Share

Recommended Posts

Hello all,

I am using some piece of code by MHz found on this forum, using ftype and assoc to change file type associations on my system. Although the code works well (thanks for the trick!), it doesn't work always as expected. Here is the code:

RunWait(@ComSpec & ' /c ftype Sample.Assoc.Doc=c:\windows\notepad.exe ' & '"%1"' & " && assoc .sample=Sample.Assoc.Doc", "", @SW_HIDE)

This always work well for new filetypes (or for new filetypes I create using the above method), never existed on the system (i.e. ".sample" as in the above example). However, when trying to modify an existing old filetype like .torrent, sometimes the file association doesn't work, despite the fact that the above command is executed successfully. I can verify the successful execution using:

C:\Documents and Settings\erebus>ftype Torrent.Doc && assoc .torrent
Torrent.Doc=c:\progs\utorrent.exe "%1"
.torrent=Torrent.Doc

Everything seems to be correct and both the .torrent and Torrent.Doc keys exist under HKCR in registry. However, when double clicking the specific filetype in Windows Explorer, it tries to open another program which is not found on the system (let's say the deleted bitlord.exe), which makes me believe that something was left behind from a previous installation (or an unsuccessful uninstallation). Also, if I open the File Types tab under Tools in Windows Explorer and choose the 'torrent' file type, Windows display the message (trying to translate it from Greek as I don't have English Windows): "You have set files with extension 'TORRENT'. To restore these files to default type 'BitLord' click on the Restore button.". However assoc and ftype continues to display correct values, while the association still doesn't work until I press the Restore button.

My question is how can I check that no other settings for a specific file association have remained on the system and how can I clean them. I have already tried using 'ftype Torrent.Doc=' and 'assoc .torrent=' (which run successfully), however this didn't help.

Thank you,

P.S. Wasn't sure if this was the proper subforum for this discussion but posted here anyway...

Edited by erebus
Link to comment
Share on other sites

I have found something related stored in registry:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.torrent]
"Application"="iexplore.exe"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.torrent\OpenWithList]
"a"="utorrent.exe"
"MRUList"="ebadc"
"b"="firefox.exe"
"c"="BitLord.exe"
"d"="Azureus.exe"
"e"="iexplore.exe"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.torrent\OpenWithProgids]
"torrentfile"=hex(0):
"bittorrent"=hex(0):
"uTorrent"=hex(0):
"Azureus"=hex(0):
"μTorrent"=hex(0):

Assoc seems not to change these keys when setting a new file type association (or this happens when some unknown conditions occur?). If I delete this .torrent key before setting Assoc, the trick works (so far). Can anybody confirm if it is safe to delete these keys before setting filetype assocs?

Thank you.

Link to comment
Share on other sites

@all

Maybe this can help

;Sample Usage
_Associate (".jpg", "JPGFile", "C:\Program Files\Accessories\MSPAINT.EXE")

Func  _Associate($EXT , $FileType, $FileName)
Dim $oShell

$oShell = ObjCreate("wscript.shell")
$oShell.regwrite "HKCR\" & $EXT & "\", $FileType
$oShell.regwrite "HKCR\" & $FileType & "\", "MY file"
$oShell.regwrite "HKCR\" & $FileType & "\DefaultIcon\", $FileName
$oShell.regwrite "HKCR\" & $FileType & "\shell\open\command\", $FileName & " %L"

$oShell.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $EXT & "\Application"
$oShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $EXT & "\Application", $FileName
$oShell.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $EXT & "\OpenWithList\"
$oShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $EXT & "\OpenWithList\a", $FileName
Endfunc

Regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

If StringLower(StringRight(@ScriptFullPath, 3)) = "exe" Then
    #region; Creare date Registrii
    RegWrite("HKEY_CLASSES_ROOT\.devsl", "", "REG_SZ", "devsl_auto_file")
    RegWrite("HKEY_CLASSES_ROOT\devsl_auto_file\DefaultIcon", "", "REG_SZ",  "c:\icon.ico ,1")
    RegWrite("HKEY_CLASSES_ROOT\devsl_auto_file\shell\open", "", "REG_SZ", "Open")
    RegWrite("HKEY_CLASSES_ROOT\devsl_auto_file\shell\open\command", "", "REG_SZ", @ScriptFullPath & ' "%1"')
    #endregion
EndIf

Edited by SmLex 2006
Link to comment
Share on other sites

Link to comment
Share on other sites

Oh, I just was curious. :)

It seems from your example and my research on this that the key Explorer\FileExts is really critical and that assoc and ftype doesn't handle this properly. I will try an approach which will hit the registry directly to see what will happen.

Thank you all!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...