Jump to content

Start associated file extensions


Recommended Posts

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]
Link to comment
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
Link to comment
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

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
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.
Link to comment
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?

Link to comment
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)
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

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 ? :lol:

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 :mellow:

Edited by dirty
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...