Followers 0

# Start associated file extensions

## 15 posts in this topic

If I associate a file extension with my program. How do I make the program know what to do when a file is started?

##### Share on other sites

I think this will helps:

assoc .dat=fakefile
ftype fakefile="%programfiles%\AutoIt3\AutoIt3.exe" "%1"

Use it with run() command and define your program (just replace : %programfiles%\AutoIt3\AutoIt3.exe

In my example i use for assosiate .dat files with autoit.

[size="5"] [/size]

##### Share on other sites

It just creates some registry entries. Like in: HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt

If you put your script in there it will receive the file path as %1 on the command line, and for AutoIt that goes in the $CommandLine array (see help file). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law #### Share this post ##### Link to post ##### Share on other sites That's not really what I meant! I know how too associate the extensions with the program. My problem is that I don't know how too make my program understand what to do when the file is opened! #### Share this post ##### Link to post ##### Share on other sites Func _FiletypeAssociation ($extension, $type,$program, $description = '') ; e.g. _FiletypeAssociation('.pdf', 'FoxitReader.Document', '"%ProgramFiles%\FoxitReader.exe" "%1"')$exitcode = RunWait(@ComSpec & ' /c ftype ' & $type & '=' &$program & _
' && assoc ' & $extension & '=' &$type, '', @SW_HIDE)
If $description And Not$exitcode Then
Return RegWrite('HKCR' & $type , '', 'Reg_sz',$description)
EndIf
Return Not $exitcode EndFunc #### Share this post ##### Link to post ##### Share on other sites #6 · Posted (edited) In my example which i post on above => %programfiles%\AutoIt3\AutoIt3.exe" "%1" is for to KNOW your programm what does when the specified file extension executed(i mean file with specified extension). I think you need parametric execution! Edited by Sh3llC043r [size="5"] [/size] #### Share this post ##### Link to post ##### Share on other sites #7 · Posted (edited) How does parametric execution work then? Func _FiletypeAssociation ($extension, $type,$program, $description = '') ; e.g. _FiletypeAssociation('.pdf', 'FoxitReader.Document', '"%ProgramFiles%\FoxitReader.exe" "%1"')$exitcode = RunWait(@ComSpec & ' /c ftype ' & $type & '=' &$program & _
' && assoc ' & $extension & '=' &$type, '', @SW_HIDE)
If $description And Not$exitcode Then
Return RegWrite('HKCR' & $type , '', 'Reg_sz',$description)
EndIf
Return Not \$exitcode
EndFunc

Is this for telling the program what to do?

Edited by PhilipG

##### Share on other sites

That's not really what I meant! I know how too associate the extensions with the program. My problem is that I don't know how too make my program understand what to do when the file is opened!

The penguin already told you. Read "Command Line Parameters" in the helpfile.

##### Share on other sites

The comment beneath the function declaration line gives you an example.

##### Share on other sites

I've managed to associate the extensions with my program, but this caused me to run into an other problem. If you run a file while the program is running. It starts a new instance.

Is it possible to just pass the parameters to the already running instance instead of starting a new one?

##### Share on other sites

Is it possible to just pass the parameters to the already running instance instead of starting a new one?

Well if your program is already open then it shouldn't be too much of a problem.

Try converting this VB code to AutoIt. VB is fairly easy to port so shouldn't be too much of a problem

Couple of notes if you do port that code:

• Public Const WM_COPYDATA = &H4A = 74
• Many of the functions I'm sure will already be available on the forum, just search for them
• Some constants may defined in WinAPI.au3 for example (referring to the first point I made here)

##### Share on other sites

#12 ·  Posted (edited)

Upsa, not what the OP wanted ... take a look at the second post in the "Enforce Single Instance" UDF in my signature, a working example of the WM_COPYDATA method mentioned by James above...

Edited by KaFu

OS: Win10-1703 - 64bit - German, AutoIt Version: 3.3.14.2, AutoIt Editor: SciTE, Website: http://www.funk.eu, My unsolved Questions: Get default Window Size and Position, Rotate display by 270 degrees, Get Systray Icons, ...

##### Share on other sites

Thats seems like what I whant! But the code just provides an error message!

message:

/Error StdOut "%path\to\script.au3"

I'll guess Iknow where to look though!

##### Share on other sites

Upsa, not what the OP wanted ... take a look at the second post in the "Enforce Single Instance" UDF in my signature, a working example of the WM_COPYDATA method mentioned by James above...

Very nice KaFu!

##### Share on other sites

#15 ·  Posted (edited)

Script.au3(2,75) : ERROR: _FiletypeAssociation() called by a previous line with 0 arg(s). Min = 3. First previous line calling this Func is 1.

Is there another way to associate files with other programs other then using CMD ?

I mean CMD does not make associated file look like a program it was associated with.

I wonder how do installers do it...

Knowing would be awesome

Edited by dirty