Talk:File Association: Difference between revisions
(Error on file association) |
(→New OpenWithProgIds Association: new section) |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
I have a problem, while trying to associate a file, under Windows XP, everything works fine, but on Windows 2000, when I try to open a file, it looks like the path is not managed in the correct way, this is the way the file path is being sent on my application c:\prog~1\archi~1 | I have a problem, while trying to associate a file, under Windows XP, everything works fine, but on Windows 2000, when I try to open a file, it looks like the path is not managed in the correct way, this is the way the file path is being sent on my application c:\prog~1\archi~1 | ||
so, i don´t know what´s going on, i´d | so, i don´t know what´s going on, i´d really apreciate your help. | ||
I think the problem is in this line | |||
WriteRegStr HKCR "ReportUncompressor.Script\shell\open\command" "" '"ReportUncompressor.exe" "%1"' | |||
oscargl2017@hotmail.com | oscargl2017@hotmail.com | ||
----- | |||
The 'OptionsFile' correspondant Registry key is only deleted when the association was in possession of another application before. | |||
-decimad | |||
I had to change the line | |||
WriteRegStr HKCR "OptionsFile\shell\edit\command" "" \ | |||
'$INSTDIR\execute.exe "%1"' | |||
to: | |||
WriteRegStr HKCR "OptionsFile\shell\edit\command" "" \ | |||
'"$INSTDIR\execute.exe" "%1"' | |||
(Put quotation marks around the path to my execute.exe). | |||
Otherwise when opening a file its path got truncated something like: c:\Prog~1\blabla~1\. | |||
My system is Windows XP, haven't tested it with other versions. | |||
----- | |||
One other thing; you may also have to update the user's explorer fileexts list before a file association change actually takes (the items in this list override those in HKCR). | |||
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts | |||
[[User:ZeBoxx|ZeBoxx]] 20:21, 25 February 2009 (UTC) | |||
----- | |||
Hi. I've tried this using NSIS 2.44 and this doesn't seem to work. According to the compiler output the file is included, and there are message about registerExtension/unregisterExtension, but when i install the software and try to open a file with my extension, windows open the usual window asking which software should be used. | |||
The example on this page is fairly straightforward, i copy/pasted it and i can't see what i could have done wrong... :-( | |||
If i use regedit, it seems that on my computer most extensions are associated with something identifying the file (mimetype or something else i dont know). While if i run my installer, the key "My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.myext" has keys REG_SZ set to the executable i give in first arg to registerExtension... i'm getting confused somehow. | |||
Orzel - may 4th, 2009, i'm using Windows XPsp2 | |||
----- | |||
Nscaveman - June 10, 2009 - Where can I find Util.nsh? | |||
== Error Flag after calling (Un)RegisterExtension == | |||
In my installer script I'm quite pedantic about checking the error flag, so I know when something is going wrong. | |||
I have found that after calling ${RegisterExtension} or ${UnRegisterExtension}, the error flag was set, although it seemed as if my file extension changes were applied correctly. | |||
[I used the script FileAssociation.nsh as of 22/10/2013, with NSIS 2.46] | |||
I made a few changes to FileAssociation.nsh by checking the Error Flag after ReadRegStr. After these modifications everything was fine and no false-positive errors were reported anymore. | |||
For the benefit of other users I post my changes in diff format below: | |||
<highlight-diff> | |||
# HG changeset patch | |||
# User PeterSchuebel | |||
# Date 1382453254 -3600 | |||
# Tue Oct 22 15:47:34 2013 +0100 | |||
# Branch bronze | |||
# Node ID 4b8b38d29c9731330e9e70c64aeb980f70f8b159 | |||
# Parent 1670a88b1bf5e3ea8cd47462f2c141a30daf5fa9 | |||
installer: FileAssociation: Do IfErrors check after ReadRegStr to prevent bogus | |||
errors. | |||
diff -r 1670a88b1bf5 -r 4b8b38d29c97 FileAssociation.nsh | |||
--- a/FileAssociation.nsh Tue Oct 22 15:47:32 2013 +0100 | |||
+++ b/FileAssociation.nsh Tue Oct 22 15:47:34 2013 +0100 | |||
@@ -118,6 +118,8 @@ | |||
Push $1 | |||
ReadRegStr $1 HKCR $R1 "" ; read current file association | |||
+ IfErrors NoBackup CheckBackup | |||
+CheckBackup: | |||
StrCmp "$1" "" NoBackup ; is it empty | |||
StrCmp "$1" "$R0" NoBackup ; is it our own | |||
WriteRegStr HKCR $R1 "backup_val" "$1" ; backup current value | |||
@@ -125,6 +127,7 @@ NoBackup: | |||
WriteRegStr HKCR $R1 "" "$R0" ; set our file association | |||
ReadRegStr $0 HKCR $R0 "" | |||
+ IfErrors 0 #basically ignore any error from non-existing reg key | |||
StrCmp $0 "" 0 Skip | |||
WriteRegStr HKCR "$R0" "" "$R0" | |||
WriteRegStr HKCR "$R0\shell" "" "open" | |||
@@ -166,9 +169,15 @@ Skip: | |||
Push $1 | |||
ReadRegStr $1 HKCR $R0 "" | |||
- StrCmp $1 $R1 0 NoOwn ; only do this if we own it | |||
+ IfErrors NoOwn CheckSame | |||
+CheckSame: | |||
+ StrCmp $1 $R1 ReadBackup NoOwn ; only do this if we own it | |||
+ReadBackup: | |||
ReadRegStr $1 HKCR $R0 "backup_val" | |||
- StrCmp $1 "" 0 Restore ; if backup="" then delete the whole key | |||
+ IfErrors DeleteWhole CheckRestore | |||
+CheckRestore: | |||
+ StrCmp $1 "" DeleteWhole Restore ; if backup="" then delete the whole key | |||
+DeleteWhole: | |||
DeleteRegKey HKCR $R0 | |||
Goto NoOwn | |||
</highlight-diff> | |||
== New OpenWithProgIds Association == | |||
Since Windows Vista it's easier and more versatile just to add own application to the list: | |||
HKCR\.myext\OpenWithProgIds | |||
See https://msdn.microsoft.com/en-us/library/bb166549.aspx | |||
[[User:Xmedeko|Xmedeko]] ([[User talk:Xmedeko|talk]]) 08:12, 15 June 2017 (UTC) |
Latest revision as of 08:12, 15 June 2017
I have a problem, while trying to associate a file, under Windows XP, everything works fine, but on Windows 2000, when I try to open a file, it looks like the path is not managed in the correct way, this is the way the file path is being sent on my application c:\prog~1\archi~1 so, i don´t know what´s going on, i´d really apreciate your help.
I think the problem is in this line
WriteRegStr HKCR "ReportUncompressor.Script\shell\open\command" "" '"ReportUncompressor.exe" "%1"'
oscargl2017@hotmail.com
The 'OptionsFile' correspondant Registry key is only deleted when the association was in possession of another application before.
-decimad
I had to change the line
WriteRegStr HKCR "OptionsFile\shell\edit\command" "" \ '$INSTDIR\execute.exe "%1"'
to:
WriteRegStr HKCR "OptionsFile\shell\edit\command" "" \ '"$INSTDIR\execute.exe" "%1"'
(Put quotation marks around the path to my execute.exe).
Otherwise when opening a file its path got truncated something like: c:\Prog~1\blabla~1\. My system is Windows XP, haven't tested it with other versions.
One other thing; you may also have to update the user's explorer fileexts list before a file association change actually takes (the items in this list override those in HKCR).
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
ZeBoxx 20:21, 25 February 2009 (UTC)
Hi. I've tried this using NSIS 2.44 and this doesn't seem to work. According to the compiler output the file is included, and there are message about registerExtension/unregisterExtension, but when i install the software and try to open a file with my extension, windows open the usual window asking which software should be used. The example on this page is fairly straightforward, i copy/pasted it and i can't see what i could have done wrong... :-(
If i use regedit, it seems that on my computer most extensions are associated with something identifying the file (mimetype or something else i dont know). While if i run my installer, the key "My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.myext" has keys REG_SZ set to the executable i give in first arg to registerExtension... i'm getting confused somehow.
Orzel - may 4th, 2009, i'm using Windows XPsp2
Nscaveman - June 10, 2009 - Where can I find Util.nsh?
Error Flag after calling (Un)RegisterExtension
In my installer script I'm quite pedantic about checking the error flag, so I know when something is going wrong. I have found that after calling ${RegisterExtension} or ${UnRegisterExtension}, the error flag was set, although it seemed as if my file extension changes were applied correctly. [I used the script FileAssociation.nsh as of 22/10/2013, with NSIS 2.46]
I made a few changes to FileAssociation.nsh by checking the Error Flag after ReadRegStr. After these modifications everything was fine and no false-positive errors were reported anymore.
For the benefit of other users I post my changes in diff format below:
# HG changeset patch # User PeterSchuebel # Date 1382453254 -3600 # Tue Oct 22 15:47:34 2013 +0100 # Branch bronze # Node ID 4b8b38d29c9731330e9e70c64aeb980f70f8b159 # Parent 1670a88b1bf5e3ea8cd47462f2c141a30daf5fa9 installer: FileAssociation: Do IfErrors check after ReadRegStr to prevent bogus errors. diff -r 1670a88b1bf5 -r 4b8b38d29c97 FileAssociation.nsh --- a/FileAssociation.nsh Tue Oct 22 15:47:32 2013 +0100 +++ b/FileAssociation.nsh Tue Oct 22 15:47:34 2013 +0100 @@ -118,6 +118,8 @@ Push $1 ReadRegStr $1 HKCR $R1 "" ; read current file association + IfErrors NoBackup CheckBackup +CheckBackup: StrCmp "$1" "" NoBackup ; is it empty StrCmp "$1" "$R0" NoBackup ; is it our own WriteRegStr HKCR $R1 "backup_val" "$1" ; backup current value @@ -125,6 +127,7 @@ NoBackup: WriteRegStr HKCR $R1 "" "$R0" ; set our file association ReadRegStr $0 HKCR $R0 "" + IfErrors 0 #basically ignore any error from non-existing reg key StrCmp $0 "" 0 Skip WriteRegStr HKCR "$R0" "" "$R0" WriteRegStr HKCR "$R0\shell" "" "open" @@ -166,9 +169,15 @@ Skip: Push $1 ReadRegStr $1 HKCR $R0 "" - StrCmp $1 $R1 0 NoOwn ; only do this if we own it + IfErrors NoOwn CheckSame +CheckSame: + StrCmp $1 $R1 ReadBackup NoOwn ; only do this if we own it +ReadBackup: ReadRegStr $1 HKCR $R0 "backup_val" - StrCmp $1 "" 0 Restore ; if backup="" then delete the whole key + IfErrors DeleteWhole CheckRestore +CheckRestore: + StrCmp $1 "" DeleteWhole Restore ; if backup="" then delete the whole key +DeleteWhole: DeleteRegKey HKCR $R0 Goto NoOwn
New OpenWithProgIds Association
Since Windows Vista it's easier and more versatile just to add own application to the list:
HKCR\.myext\OpenWithProgIds
See https://msdn.microsoft.com/en-us/library/bb166549.aspx Xmedeko (talk) 08:12, 15 June 2017 (UTC)