- NSIS Discussion
- File Association Problem
Archive: File Association Problem
jcagle
29th July 2003 04:26 UTC
File Association Problem
I got my file to associate to my application. However, the icon is not getting assigned to the file. Here is my code...it's basically copied directly out of Examples\makensis. Any ideas what is happening?
By the way, I use RefreshShellIcons and I've also rebooted to see if that associates the icon, but those don't work either. Thanks!!!
;Back up old value of .opt
ReadRegStr $1 HKCR ".h2h" ""
StrCmp $1 "" NoBackup
StrCmp $1 "H2H.Document" NoBackup
WriteRegStr HKCR ".h2h" "backup_val" $1
NoBackup:
WriteRegStr HKCR ".h2h" "" "H2H.Document"
ReadRegStr $0 HKCR "H2H.Document" ""
StrCmp $0 "" 0 skipOPTAssoc
WriteRegStr HKCR "H2H.Document" "" "H2H File"
WriteRegStr HKCR "H2H.Document\shell" "" "open"
WriteRegStr HKCR "H2H.Document\DefaultIcon" "" $INSTDIR\${MUI_FILE},1
skipOPTAssoc:
WriteRegStr HKCR "H2H.Document\shell\open\command" "" '$INSTDIR\${MUI_FILE} "%1"'
Vytautas
29th July 2003 07:29 UTC
Try this code:
;Back up old value of .opt
ReadRegStr $1 HKCR ".h2h" ""
StrCmp $1 "" NoBackup
StrCmp $1 "H2H.Document" NoBackup
WriteRegStr HKCR ".h2h" "backup_val" $1
NoBackup:
WriteRegStr HKCR ".h2h" "" "H2H.Document"
ReadRegStr $0 HKCR "H2H.Document" ""
StrCmp $0 "" 0 skipOPTAssoc
WriteRegStr HKCR "H2H.Document" "" "H2H File"
WriteRegStr HKCR "H2H.Document\shell" "" "open"
WriteRegStr HKCR "H2H.Document\DefaultIcon" "" $INSTDIR\${MUI_FILE},0
skipOPTAssoc:
WriteRegStr HKCR "H2H.Document\shell\open\command" "" '$INSTDIR\${MUI_FILE} "%1"'
Note the 0 on the 3rd last line. I think that your exe has only 1 icon and since the icon list starts from 0 windows cannot find the 2nd icon, which does NOT exist. :)
Vytautas
jcagle
29th July 2003 14:13 UTC
You are correct...my .exe only has one icon. I'll give your example a try and let you know how it turns out!!! Thanks!!
jcagle
29th July 2003 14:33 UTC
Ok, it worked...but, not like expected!
First, since my last installation/uninstallation left the H2H.Document (see above example) in the registry, the change from:
WriteRegStr HKCR "H2H.Document\DefaultIcon" "" $INSTDIR\${MUI_FILE},1
to:
WriteRegStr HKCR "H2H.Document\DefaultIcon" "" $INSTDIR\${MUI_FILE},0
did not occur properly...so, I had to do it manually. But, THEN it worked!
Second (now for the unexpected part), when I associate the files via the Folder Options...|File Types, the icon of the files has the icon of the .exe on a piece of paper...similar to how a .doc looks. This is what I want it to look like (the "on a piece of paper" way, that is). However, doing it the "makensis" way, I actually get the same icon as the .exe. Does anyone have any ideas on how to programmatically do what the Folder Options... is doing?
Vytautas
29th July 2003 14:40 UTC
Not sure about that one, which version of Windows do you have since the Folder Options way is supposed to have the same icon, i.e. identical to your exe icon. Usually if you want a document icon to have a 'paper' in the background you would have to create another icon which look like that and include that icon in either the exe file or as an .ico file with your installation.
Vytautas
jcagle
29th July 2003 15:45 UTC
That's interesting. It did it on Windows ME, but I can't re-produce it on Windows 2000 Professional!?!?!? If someone has Windows ME, could you try to use Folder Options... and associate a file and see what happens? I'm away from my home PC right now (which has Windows ME), else I would try it myself.
jcagle
30th July 2003 13:36 UTC
I don't know why, but I can't get this to work anymore. At one time, I associated my files with an icon, and the resulting desktop icon was my selected icon on a "blank sheet of paper" icon...like the .doc icon where the "W" is on the blank sheet of paper. Since I did it once, I'm assuming that I can do it again. Does anyone know how this is done?
Afrow UK
30th July 2003 14:33 UTC
In Folder Options, I achieve it by telling my .bsp file extension to open in a certain program (in my case Quake2maX) and it shows the Quake2maX icon on a piece of paper as the file extension logo.
It's only after I click "Change Icon" that I can force Windows to display the full exe logo on my .bsp file icons.
-Stu
jcagle
30th July 2003 15:04 UTC
Can this be accomplished with setting some registry settings while doing an file association during installation? (that you know of?)
Afrow UK
30th July 2003 15:37 UTC
Try
WriteRegStr HKCR ".bsp" "" "BSPFile"
WriteRegStr HKCR "BSPFILE\Shell\Open\Command" "C:\quake2\quake2max.exe"
Make sure you config it to your own file extension.
-Stu
Afrow UK
30th July 2003 15:39 UTC
You should look at this:
http://nsis.sourceforge.net/archive/...instances=0,11
The WriteRegStr that writes the DefaultIcon value sets the icon of your extension.
Without this, Windows will (I think) just put the application logo on a piece of paper.
-Stu
jcagle
30th July 2003 16:33 UTC
The link you sent me is exactly what I tried...but, it just uses the application logo...not the logo on a piece of paper.
One of the things I see different between what you posted and in the link gave, is:
WriteRegStr HKCR "BSPFILE\Shell\Open\Command" "C:\quake2\quake2max.exe"
as opposed to this:
WriteRegStr HKCR "BSPFILE\Shell\Open\Command" "" 'C:\quake2\quake2max.exe "%1"'
Have you used your posting in an actual application? Did it put your logo on a piece of paper?
Afrow UK
30th July 2003 16:39 UTC
Use the same code I gave you the link to, but remove...
WriteRegStr HKCR "OptionsFile\DefaultIcon" "" $INSTDIR\execute.exe,0
...from the script.
-Stu
jcagle
30th July 2003 17:19 UTC
I will give that a shot when I get back to my home PC (which is where my app is). Thanks a lot for your help!!!
jcagle
31st July 2003 01:01 UTC
I finally got this to work...kind of...I could only get it to work if the $INSTDIR was in DOS format (you know, with the ~1 etc...) in the following line:
WriteRegStr HKCR "H2H.Document\shell\open\command" "" '$INSTDIR\${MUI_FILE} "%1"'
So, I guess I have 2 questions:
1) Is that really the case? To get this to work properly, do I really have to have the DOS format for the path?
2) If I DO have to have it in DOS format, is there some sort of converter that I can use in my NSIS script that will do this conversion for me?
Thanks!!
Afrow UK
31st July 2003 11:11 UTC
Have a look in NSIS documentation.
I thinks theres a command to convert paths to DOS format.
-Stu
Afrow UK
31st July 2003 11:12 UTC
Try this:
WriteRegStr HKCR "H2H.Document\shell\open\command" "" "$\"$INSTDIR\${MUI_FILE}$\" $\"%1$\""
-Stu
jcagle
31st July 2003 14:10 UTC
I didn't try your example, Afrow, but I did get this to work:
GetFullPathName /SHORT $R1 $INSTDIR
WriteRegStr HKCR "H2H.Document\shell\open\command" "" "$R1\${MUI_FILE} %1"
Do you think your example is a better way of doing it, or is this way better?
Afrow UK
31st July 2003 16:15 UTC
Mine will be better.
I'm simply placing quotes " " around the parts, as I expect it's not working correctly because $INSTDIR has spaces in it.
-Stu
jcagle
31st July 2003 18:01 UTC
I'll give your way a shot and let you know how it turns out, Afrow. And, as usual, Thanks a lot for your help!
Afrow UK
31st July 2003 20:13 UTC
No problem :)
I like to help!
-Stu [15 year old kid]