View Full Version : File association question
augustwind
02-23-2007, 10:34 AM
Is there a way to create a new screen in the installation, that lists the possible file associations for my application, so that the end user can check or uncheck them?
Also - is there a way to add my application to the 'Open With' menu for any file associations (whether they're selected for association or not)?
You would need to use a checkbox screen to accomplish this.
Adam Kapilik
augustwind
02-28-2007, 10:08 PM
I've got scripts that correctly work, assigning variables for each filetype checked in the Checkboxes screen.
then, in the Ready To Install screen - before Screen.Next:
I have this, for Text Files (using TextFile variable):
if SessionVar.Get("%TextFile%")=="True" then
Registry.SetValue(HKEY_CLASSES_ROOT, ".txt", "", "MyAppName", REG_SZ);
Registry.SetValue(HKEY_CLASSES_ROOT, "MyAppName\\\\shell\\\\open\\\\command", "", SessionVar.Expand("%AppFolder%\\\\MyAppName.exe\\\"%1\""), REG_SZ);
Registry.SetValue(HKEY_CLASSES_ROOT, "MyAppName\\\\DefaultIcon", "", SessionVar.Expand("%AppFolder%\\\\MyAppName.exe ,0\\"), REG_SZ);
end
However, it still doesn't work - it doesn't associate my application with text files (*.txt files)
What am I doing wrong?
open regedit and check if keys have been created
if yes, and it still doesn't work, then these are not the correct keys to create.
To speed up testing first make a .reg file that sets the file associations, and test it until they are properly set - then create & test SF code that makes the same keys.
imo keys have to be created (for .txt files) under
HKEY_CLASSES_ROOT\txtfile
,not under HKEY_CLASSES_ROOT\.txt, however I'm not sure as I'm on another PC now. Anyway, if you make it with a .reg file, the rest should be easy.
---
BTW I would love to see a feature to manage file associations in the SF7 projects, so that we don't have to set keys through code and care about eventual OS-specific issues when doing this.
augustwind
05-13-2007, 01:28 AM
For some reason, I can just NOT get this association deal working and it's driving me crazy having not only learn all this, but to manually run this, without any way to test other than compiling and running the install app:
I've got a checkbox page, with a .TXT checkbox - lua variable chktxt.
I found another project showing how to check it, and it is showing correctly, whether checked or not. Here's the code:
if chktxt then
Registry.SetValue(HKEY_CLASSES_ROOT, ".txt", "", "MyApp", REG_SZ);
Registry.SetValue(HKEY_CLASSES_ROOT, "MyApp\\\shell\\\\open\\\\command", "", SessionVar.Expand("%AppFolder%\\\\MyApp.exe\\\"%1\""), REG_SZ);
Registry.SetValue(HKEY_CLASSES_ROOT, "MyApp\\\\DefaultIcon", "", SessionVar.Expand("%AppFolder%\\\\MyApp.exe ,0\\"), REG_SZ);
end
I"m thinking it might have something to do with the syntax above, or the number of slashes, which is very frustrating, since I really have no earthly idea on how many slashes to put and where.
This really should have more automation assigned to it (are you listening?)!!
I then double click on a text file and it opens in Notepad - NOT what I wanted.
I'll need to go to some other solution I can't get this working. Please help!
augustwind
05-13-2007, 01:07 PM
1. the TXTFile registry setting never gets changed from Notepad. I manually changed it, and at least my application opens, when a text file is double-clicked
2. the paths that get put in the registry are wrong, based on the knowledgebase article, and the other help I've gotten - it puts 2 slashes in the path before myApp.exe and it messes with the %1% that's supposed to be in there - - don't know for sure, but I don't think that needs to have quotes around it.
3. the default Icon never gets changed, and it must be what gets put in the path there also, that's the problem, but I don't know what the registry is supposed to have in it for that value.
I just need a definitive script - I've been fiddling with this on and off for over 3 months now - and that's totally ridiculous - I need a complete solution for a file association!
Desolator
05-13-2007, 04:09 PM
--[[
Function: SetFileAssociation
Purpose: A function that will create file associations.
Arguments:
strApplicationPath - The path to the application executable file.
strIconFile - The path to the application icon file.
strFileExtension - The extension to associate.
Returns: Nothing. You can use Application.GetLastError to determine whether this action failed, and why.
Example: SetFileAssociation(_SourceFolder .. "\\" .. _SourceFilename, String.Replace(_SourceFolder .. "\\" .. _SourceFilename, ".ico", ".exe", false), ".ogg", );
]]--
function SetFileAssociation(strApplicationPath, strFileExtension, strIconFile)
Registry.SetValue(HKEY_CLASSES_ROOT, strFileExtension, "", File.GetShortName(strApplicationPath));
Registry.SetValue(HKEY_CLASSES_ROOT, strAppShortName.."\\shell\\open\\command", "", "\""..strApplicationPath.."\" \"%1\"");
Registry.SetValue(HKEY_CLASSES_ROOT, strAppShortName.."\\DefaultIcon", "", File.GetShortName(strIconFile)..",0");
end
I made this for AMS, but should work on SUF, too.
augustwind
05-13-2007, 09:11 PM
OK - please help me with understanding the example -- subsitute c:\windows\system3\Notepad.exe and .txt files in the following example line:
Example: SetFileAssociation(_SourceFolder .. "\\" .. _SourceFilename, String.Replace(_SourceFolder .. "\\" .. _SourceFilename, ".ico", ".exe", false), ".ogg", );
Desolator
05-14-2007, 03:33 AM
Here it is:
SetFileAssociation("c:\\windows\\system3\\Notepad.exe", "c:\\windows\\system3\\Notepad.exe", ".txt", );
augustwind
05-14-2007, 10:46 PM
a couple of questions here -
the way you have the example of notepad, the arguments are in a different order than the function - - is that still right?
I moved them around, in what I thought would be right, placing the .txt extension in the middle of the call to the function -
However I get an error:
On Next, Line 7: attempt to concatenate global 'strAppShortName' (a nil value)
Also - what's with the red periods in the function?
Plus - where in the arguments am I supposed to set the appshortname? I ended up hardcoding it in - here's what I ended up with in the functioN:
function SetFileAssociation(strApplicationPath, strFileExtension, strIconFile)
Registry.SetValue(HKEY_CLASSES_ROOT, strFileExtension, "", File.GetShortName(strApplicationPath));
Registry.SetValue(HKEY_CLASSES_ROOT, "iWrite Professional\\shell\\open\\command", "", "\""..strApplicationPath.."\" \"%1\"");
Registry.SetValue(HKEY_CLASSES_ROOT, "iWrite Professional\\DefaultIcon", "", File.GetShortName(strIconFile)..",0");
end
I don't get the 'strIconfile' either - does it get the default Icon from the EXE?
You do know that your original sample call has much more syntax/arguments than what you gave me in the last post, right?
Here's what I put in the actual call:
SetFileAssociation("%AppFolder%\\MyApp.exe", ".txt", "%AppFolder%\\MyApp.exe");
Still - it doesn't work - and it doesn't change HKEY Root's TXTFile designation
I double click on a file - it opens up Notepad.
I'll admit that I don't really know the ends and outs of this action scripting language, but this seems to be really more complicated than it should be. I'm beginning to hate having to learn another language just to do this one thing.
GnaisH
07-05-2007, 08:16 PM
In case anybody runs across this like I did trying to set File extensions in SUF, the function given by Desolator works but it needs a few modifications. This is what I changed to get it working:
function SetFileAssociation(strApplicationPath, strIconFile, strFileExtension)
Registry.SetValue(HKEY_CLASSES_ROOT, strFileExtension, "", File.GetShortName(strApplicationPath));
Registry.SetValue(HKEY_CLASSES_ROOT, File.GetShortName(strApplicationPath).."\\shell\\open\\command", "", "\""..strApplicationPath.."\" \"%1\"");
Registry.SetValue(HKEY_CLASSES_ROOT, File.GetShortName(strApplicationPath).."\\DefaultIcon", "", File.GetShortName(strIconFile)..",0");
end
This will solve the problem of the following error:
"attempt to concatenate global 'strAppShortName' (a nil value)"
artistscope
02-11-2008, 10:37 AM
I am finding that when using %AppFolder% in a script to create a registry key, it is not being converted. It still reads as %AppFolder% for example...
Registry.SetValue(HKEY_CLASSES_ROOT, "NewType.Document\\shell\\open\\command", "NoName", "%AppFolder%\\NewTypeReader.exe \"%1\"", REG_SZ);
ends up in the registry as...
%AppFolder%\NewTypeReader.exe "%1"
%AppFolder% is not translated??
What's missing here?
jassing
02-11-2008, 11:52 AM
I am finding that when using %AppFolder% in a script to create a registry key, it is not being converted. It still reads as %AppFolder% for example...
Registry.SetValue(HKEY_CLASSES_ROOT, "NewType.Document\\shell\\open\\command", "NoName", "%AppFolder%\\NewTypeReader.exe \"%1\"", REG_SZ);
ends up in the registry as...
%AppFolder%\NewTypeReader.exe "%1"
%AppFolder% is not translated??
What's missing here?
You need to use SessionVar.Expand() or concatenate the strings with SessionVar.Get()
wunder
03-13-2008, 11:38 AM
I'm trying to use the function set up for creating associations. Here's my code from the post install area:
setfileassociations ( SessionVar.Expand("%AppFolder%").."amwin.exe",SessionVar.Expand("%AppFolder%").."amwin.exe",".am");
This doesn't cause any syntax errors, but gets the dreaded 'nil value' error when I try to run my install. I'm sure I've overlooked something obvious- any ideas?
I'm really surprised creating file associations isn't built into the program! Oh well.
jassing
03-13-2008, 11:42 AM
I'm trying to use the function set up for creating associations. Here's my code from the post install area:
setfileassociations ( SessionVar.Expand("%AppFolder%").."amwin.exe",SessionVar.Expand("%AppFolder%").."amwin.exe",".am");
This doesn't cause any syntax errors, but gets the dreaded 'nil value' error when I try to run my install. I'm sure I've overlooked something obvious- any ideas?
I'm really surprised creating file associations isn't built into the program! Oh well.
Since I don't know what "THE" dreaded 'nil value' error" is -- nor where you are getting that error... my best guess is:
do you really mean for it to translate to:
setfileassociations( "c:\program files\some diramwin.exe", "c:\program files\some diramwin.exe", ,".am")
??? Shouldn't be "c:\program files\some dir\amwin.exe"?
SessionVar.Expand( "%AppFolder%\\amwin.exe") is the better way to go.
wunder
03-13-2008, 12:14 PM
Thanks- that was part of the problem. Now the function is working properly (on post install), but the association does not seem to be created properly. When I create a '.am' file, the association is not made and it asks for an application to open it with. I looked at the registry and it created the association with the '.am' extension in HKCR/.am, with the data of the short name of my app, but it's not working. I tried using the original function creator's code which also got an error as described in the thread. Here is my final version of the code and my call. I'm sure it's something stupid- I'm just learning the product. Thanks.
Function definition in Global Functions:
--[[
Function: SetFileAssociation
Purpose: A function that will create file associations.
Arguments:
strApplicationPath - The path to the application executable file.
strIconFile - The path to the application icon file.
strFileExtension - The extension to associate.
Returns: Nothing. You can use Application.GetLastError to determine whether this action failed, and why.
Example: SetFileAssociation(_SourceFolder .. "\\" .. _SourceFilename, String.Replace(_SourceFolder .. "\\" .. _SourceFilename, ".ico", ".exe", false), ".ogg", );
]]--
function SetFileAssociation(strApplicationPath, strFileExtension, strIconFile)
Registry.SetValue(HKEY_CLASSES_ROOT, strFileExtension, "", File.GetShortName(strApplicationPath));
Registry.SetValue(HKEY_CLASSES_ROOT, File.GetShortName(strApplicationPath).."\\shell\\open\\command", "", "\""..strApplicationPath.."\" \"%1\"");
Registry.SetValue(HKEY_CLASSES_ROOT, File.GetShortName(strApplicationPath).."\\DefaultIcon", "", File.GetShortName(strIconFile)..",0");
end
Call in Post Install:
SetFileAssociation( SessionVar.Expand("%AppFolder%").."\\amwin.exe",".am",SessionVar.Expand("%AppFolder%").."\\amwin.exe");
jassing
03-13-2008, 12:19 PM
SetFileAssociation( SessionVar.Expand("%AppFolder%").."\\amwin.exe",".am",SessionVar.Expand("%AppFolder%").."\\amwin.exe");
I'll take a look at your code & check it out -- but you do realize you can skip the concatentating part:
SessionVar.Expand("%AppFolder%").."\\amwin.exe"
to a much easier to read:
SessionVar.Expand("%AppFolder%\\amwin.exe")
jassing
03-13-2008, 01:10 PM
Call in Post Install:
SetFileAssociation( SessionVar.Expand("%AppFolder%").."\\amwin.exe",".am",SessionVar.Expand("%AppFolder%").."\\amwin.exe");
Try my code:
function File.SetAssocation(cExt, cExe, cIcon, cShort,cLong)
local cKey = cShort..".Document";
Registry.SetValue(HKEY_CLASSES_ROOT, cExt, "", cKey);
Registry.SetValue(HKEY_CLASSES_ROOT, cKey, "",cLong);
Registry.SetValue(HKEY_CLASSES_ROOT, cKey.."\\DefaultIcon","",File.GetShortName(cIcon)..",1");
Registry.SetValue(HKEY_CLASSES_ROOT, cKey.."\\shell\\open\\command", "", "\""..cExe.."\" \"%1\"");
end
and then your call would be:
File.SetAssocation( ".am",SessionVar.Expand("%AppFolder%\\amwin.exe"),SessionVar.Expand("%AppFolder%\\amwin.exe","AMFILE","AMFILE");
I did minimal testing; but it seemed to work here.
wunder
03-13-2008, 01:26 PM
Thanks- seems like something is still not quite working. I copied your global code:
function File.SetAssocation(cExt, cExe, cIcon, cShort, cLong)
local cKey = cShort..".Document";
Registry.SetValue(HKEY_CLASSES_ROOT, cExt, "", cKey);
Registry.SetValue(HKEY_CLASSES_ROOT, cKey, "",cLong);
Registry.SetValue(HKEY_CLASSES_ROOT, cKey.."\\DefaultIcon","",File.GetShortName(cIcon)..",1");
Registry.SetValue(HKEY_CLASSES_ROOT, cKey.."\\shell\\open\\command", "", "\""..cExe.."\" \"%1\"");
end
And the Post Install code (which got an error missing the last ')' ):
File.SetAssocation( ".am",SessionVar.Expand("%AppFolder%\\amwin.exe"),SessionVar.Expand("%AppFolder%\\amwin.exe","AMFILE","AMFILE"));
And now I get the message:
On Post Install, Line 2: attempt to concatenate local 'cShort' (a nil value)
Not sure if I put that missing ')' in the right place...
jassing
03-13-2008, 01:30 PM
File.SetAssocation( ".am",SessionVar.Expand("%AppFolder%\\amwin.exe"),SessionVar.Expand("%AppFolder%\\amwin.exe","AMFILE","AMFILE"));
Not sure if I put that missing ')' in the right place...
You didn't it's my fault for editing your original line to be sure you dind't have to think about how to make the call...
File.SetAssocation( ".am",SessionVar.Expand("%AppFolder%\\amwin.exe"),SessionVar.Expand("%AppFolder%\\amwin.exe"),"AMFILE","AMFILE");
wunder
03-13-2008, 01:31 PM
Oops- I found part of the problem- when I posted I could easily see where that missing ) was supposed to go.
So, progress! It now opens my file. The only thing remaining is the icon for the .am file is not set up properly. I'll do some digging and see if I can get that. Thank you very much for the help.
wunder
03-13-2008, 01:41 PM
Got it- needed a ",0" instead of a ",1" for the icon. I don't know what the difference is, but my previous installation software DeployMaster did this. I changed it to ,0 and now it's working perfectly. Thanks again. If you're ever in Wisconsin, I owe you a beer.
Final functioning code:
Global:
function File.SetAssocation(cExt, cExe, cIcon, cShort, cLong)
local cKey = cShort..".Document";
Registry.SetValue(HKEY_CLASSES_ROOT, cExt, "", cKey);
Registry.SetValue(HKEY_CLASSES_ROOT, cKey, "",cLong);
Registry.SetValue(HKEY_CLASSES_ROOT, cKey.."\\DefaultIcon","",File.GetShortName(cIcon)..",0");
Registry.SetValue(HKEY_CLASSES_ROOT, cKey.."\\shell\\open\\command", "", "\""..cExe.."\" \"%1\"");
end
Post Install:
File.SetAssocation( ".am",SessionVar.Expand("%AppFolder%\\amwin.exe"),SessionVar.Expand("%AppFolder%\\amwin.exe"),"AMFILE","AMFILE");
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.