Page 1 of 1

How to really(!) associate an file extension to new program?

Posted: 13 May 2015 03:56
by pstein
In the past I registered all picture file extensions (like *.jpg, *.png, *.bmp) to be automatically opened (under 64bit Win7) with the XnView picture viewer.

Now I want to switch for them to a new viewer FastStone Image Viewer.

I want to do this programmatically from DOS batch file. Therefore I setup the following batch script
with built-in tools "assoc" and "ftype" according to this tutorial:

http://commandwindows.com/assoc.htm

reassignext.bat:

assoc .jpg=imgfile
assoc .jpeg=imgfile
assoc .bmp=imgfile
assoc .gif=imgfile
assoc .png=imgfile
ftype imgfile="D:\\viewer\\FastStone\\FSViewer.exe" "%%1"
pause


When I run it everything seems fine (=no error or warning appears).

However when I double click afterwards on a *.png file (in Windows Explorer) it is still opened with old XnView.

Why?

Do I have to reboot to take effect?

Simply coding:

ftype imgfile="D:\viewer\FastStone\FSViewer.exe" "%1"

has no effect.

How else can I (with a cmdline command) really, really associate an extension to a program?
This new association should switch the icon accordingly as well to the new viewer.

Advanced question: If possible can I tell Windows somehow to switch the program FOR all extension (not only the 5 mentioned in the batch script; There are approx 30 more) which are opened by aaa.exe to now new program bbb.exe (generally spoken)?

Thank you
Peter

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 04:03
by npocmaka_
check tis registry value

Code: Select all

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg\OpenWithList


and also for the other extensions.

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 04:28
by pstein
@npocmaka:

Ok, I have exported the Registry branch into *.reg file. It looks like:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg\OpenWithList]
"MRUList"="jbfdae"
"b"="FSViewer.exe"
"d"="Corel Paint Shop Pro Photo.exe"
"e"="i_view32.exe"
"f"="iexplore.exe"
"i"="NitroPDF.exe"
"j"="xnview.exe"
"a"="SSView.exe"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg\OpenWithProgids]
"jpegfile"=hex(0):
@=hex(0):
"FSViewer.JPG"=hex(0):
"XnView.jpg"=hex(0):

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg\UserChoice]
"Progid"="XnView.jpg"


What means "Progid" in branch "UserChoice"?

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 04:35
by npocmaka_
pstein wrote:@npocmaka:


What means "Progid" in branch "UserChoice"?


these values are changed when you right click over image and choose open with."User choice" is the same as "always use the selected program bla-blah "

It has higher prio than asoc/ftype.

If you delete the whole HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg key the assoc will start to work for jpg files.

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 04:41
by pstein
Ok, thank you.

How can I programmatically delete the mentioned Registry branch from DOS batch script?

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 04:52
by npocmaka_
most convenient way is with reg command : http://ss64.com/nt/reg.html

It is not available by default in XP and windows 2003 and installation of windows 2003 resource tool kit is needed.
Not sure about basic editions of Vista/7/8 but I think it should be there

More portable way is with regedit but deleting keys with it is cumbersome work.
There are also built-in WMIC/WMI connectors , .NET classes ...

In all cases you'll need elevated permissions.

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 05:23
by pstein
As I found out meanwhile the command is available on Win 7:

https://technet.microsoft.com/en-us/lib ... 42145.aspx

So I entered (for testing purposes) on terminal at first (not in batch script):

D:\tmp>Reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg /f
ERROR: Delete request is partially completed.

Everything is deleted except the critical subkey

UserChoice

:-(

Re-applying the command gives:

D:\tmp>Reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg /f
ERROR: Access is denied.

How do I really delete everything within a Registry key?
I have full admin control

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 05:37
by npocmaka_
try with the assoc command...

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 06:35
by carlos
If I not remember bad, reg.exe is available on windows xp professional but is missing on windows xp home edition.

About delete a key with regedit. You can delete the entire key with all values adding a - as sufix like:

Code: Select all

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Console\test]


that will delete the key HKEY_CURRENT_USER\Console\test
for delete the a specific value like a value called hello:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Console\test]
"hello"=-



source:

Code: Select all

https://support.microsoft.com/en-us/kb/310516


then, you can export the file using:

Code: Select all

regedit.exe /e file.reg

Re: How to really(!) associate an file extension to new prog

Posted: 13 May 2015 09:36
by Ed Dyreen
pstein wrote:Reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg /f
ERROR: Delete request is partially completed.

Everything is deleted except the critical subkey

UserChoice

:-(

Re-applying the command gives:

D:\tmp>Reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg /f
ERROR: Access is denied.
That's odd, are you running the batch with admin privileges ? Then try this

Code: Select all

@echo off

:: Set the owner to trustee recursive
setACL.exe -on "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg" -ot reg -actn setowner -ownr "n:Administrator" -rec yes

:: Reset permissions on all sub-objects and enable propagation of inherited permissions.
setACL.exe -on "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg" -ot reg -actn rstchldrn -rst "dacl,sacl"

:: Process ACEs specified by parameter Administrator full
setACL.exe -on "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpg" -ot reg -actn ace -ace "n:Administrator;p:full;m:set"

echo.
pause
exit
These commands require that you download setACL obviously. Then try to delete it again.