Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using PowerShell to manage file associations

2,216 views
Skip to first unread message

Larry__Weiss

unread,
Nov 9, 2009, 2:48:26 PM11/9/09
to
How can I use PowerShell to manage Windows file associations that specify a
program to handle an action for a file, depending upon the file extension
portion of the filename?

- Larry

Martin Zugec

unread,
Nov 10, 2009, 4:14:44 AM11/10/09
to
I am afraid you have to use assoc.exe or directly manipulate registry :(

Martin

"Larry__Weiss" <l...@airmail.net> wrote in message
news:O0geeWXY...@TK2MSFTNGP04.phx.gbl...

Larry__Weiss

unread,
Nov 10, 2009, 8:06:11 AM11/10/09
to
Is there anything in .NET for this?

- Larry

Martin Zugec

unread,
Nov 10, 2009, 9:11:13 AM11/10/09
to
Not that I am aware of :( There is some functionality in Visual Studio
itself when you want to publish your project, however there are not native
.NET classes\methods (again, AFAIK) that could help you.

Martin

"Larry__Weiss" <l...@airmail.net> wrote in message

news:ugIfXagY...@TK2MSFTNGP04.phx.gbl...

Larry__Weiss

unread,
Nov 10, 2009, 10:35:16 AM11/10/09
to
I'm trying to puzzle out the combination of

assoc.exe
ftype.exe

to change a file's "open" action association.

The PowerShell part should be straightforward after that.

(Again, PowerShell makes me learn many new things!)

- Larry

Oisin (x0n) Grehan [MVP]

unread,
Nov 15, 2009, 11:43:52 PM11/15/09
to
> >>  - Larry- Hide quoted text -
>
> - Show quoted text -

FTYPE and ASSOC are built-in commands for CMD.exe. They are not native
executables, and cannot be invoked from powershell (or anything
outside of cmd.exe for that matter). The fact you can invoke them
with ftype.exe is an artifact of the command search algorithm.
ftype.com also works, as does the funny-looking cls.exe, cls.com,
cls.bat or anything in %PATHEXT%:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Hope this helps,


-Oisin

Larry__Weiss

unread,
Nov 16, 2009, 9:44:30 AM11/16/09
to

Oisin (x0n) Grehan [MVP] wrote:
> FTYPE and ASSOC are built-in commands for CMD.exe. They are not native
> executables, and cannot be invoked from powershell (or anything
> outside of cmd.exe for that matter). The fact you can invoke them
> with ftype.exe is an artifact of the command search algorithm.
> ftype.com also works, as does the funny-looking cls.exe, cls.com,
> cls.bat or anything in %PATHEXT%:
>
> PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
>

To invoke built-in commands to cmd.exe from PowerShell you just execute cmd.exe
with the /c parameter. For example

cmd /c ftype /?
cmd /c assoc /?

- Larry

0 new messages