Archive: File Association / What am I doing wrong? WinXP vs. Win2K


File Association / What am I doing wrong? WinXP vs. Win2K
This piece of code seems to work on my XP box while on windows 2000 it does not?? I am also having trouble in picking up the appropriate icon from the cView (third party app). Help?!


The Code (I forgot to attach)
Function fileAssociation
;create file association
ReadRegStr $0 HKCR "Applications\cView.exe\shell\open\command" ""

StrCpy $9 " $\"%1$\""
StrCpy $1 $0
; remove end characters
Call removeFromString

; remove inital quote
StrCpy $9 "$\""
Call removeFromString

; remove end quote
StrCpy $9 "$\""
Call removeFromString

WriteRegStr HKCR ".rpt" "" "Applications\cView.exe"
WriteRegStr HKCR ".rpt\DefaultIcon" "" $1,0

WriteRegStr HKCR "Applications\cView.exe" "" "cView File"
WriteRegStr HKCR "Applications\cView.exe\shell" "" "open"
FunctionEnd


Try this code
ReadRegStr $0 HKCR "Applications\cView.exe\shell\open\command" ""

WriteRegStr HKCR ".rpt" "" "rptfile"

WriteRegStr HKCR "rtpfile\DefaultIcon" "" "$0,0"
WriteRegStr HKCR "rtpfile" "" "cView File"
WriteRegStr HKCR "rtpfile\shell\open\command" "" "$0"


See the thing is that the following line:
ReadRegStr $0 HKCR "Applications\cView.exe\shell\open\command" ""

returns something like this "c:\Profram Files\prog.exe" "%1"

That is why I have to trim it out...

Should I try your code anyways?


You don't have to trim it. Try my code.


Didn't work
When I tried to click on a rpt file a windows dialog box opened and asked me with which application I would like to open the file.


What is the value of $0? Is the icon ok?


$0 = "C:\Program Files\cView\cView.exe" "%1"


Icon is not OK either
see title


I made a typo in the code. Replace rtpfile by rptfile in the last 3 lines.


Almost there!!
It seems to start the acView application but!! it does not open the rpt file?!

I think there might be a problem with the input parameter "%1" somewhere??


What is the value of HKCR, rtpfile\shell\open\command


it is same as the one above:

$1 = "C:\Program Files\cView\cView.exe" "%1"


Try to open it manually using the command line. Does that work?


when I do start run: C:\Program Files\cView\cView.exe

works like a charm and opens up!
but when I do something like this:

C:\Program Files\cView\cView.exe file.rpt
it does not open the file

funny thing is that if I manually set it up (association) it opens the file.


I think I know where the problem is: here is the scenario...
1) i am using windows XP
2) when I got to Folder Options | File Types | then select .RPT | Advanced
3) then choose Edit
4) then delete "%1"
It starts working!!


the only question is how do I reolve this finding to code above and that the proper icon starts showing up? Your help is greatly appreciated!!


this is what got it to work!
ReadRegStr $0 HKCR "Applications\cView.exe\shell\open\command" ""
;MessageBox MB_OK "$0"

WriteRegStr HKCR ".rpt" "" "rptfile"

WriteRegStr HKCR "rptfile\DefaultIcon" "" "$0,0"
WriteRegStr HKCR "rptfile" "" "cView File"
WriteRegStr HKCR "rptfile\shell\open\command" "" "$0"

StrCpy $9 " $\"%1$\""
StrCpy $1 $0
Call removeFromString
WriteRegStr HKCR "rptfile\shell\open\command" "" "$1"


The only thing left is now the icon??