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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

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

#1 Post by pstein » 13 May 2015 03:56

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
Last edited by pstein on 13 May 2015 04:03, edited 1 time in total.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#2 Post by npocmaka_ » 13 May 2015 04:03

check tis registry value

Code: Select all

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


and also for the other extensions.

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

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

#3 Post by pstein » 13 May 2015 04:28

@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"?

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#4 Post by npocmaka_ » 13 May 2015 04:35

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.

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

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

#5 Post by pstein » 13 May 2015 04:41

Ok, thank you.

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

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#6 Post by npocmaka_ » 13 May 2015 04:52

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.

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

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

#7 Post by pstein » 13 May 2015 05:23

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

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

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

#8 Post by npocmaka_ » 13 May 2015 05:37

try with the assoc command...

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

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

#9 Post by carlos » 13 May 2015 06:35

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#10 Post by Ed Dyreen » 13 May 2015 09:36

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.

Post Reply