unclemeat
unclemeat

Reputation: 5207

How to suppress 'Open with' window

When running a file which has an unknown extension (lets say test.nope) from the command line or a batch file - using test.nope, call test.nope or start test.nope - you are presented with a window asking you to "Choose the program you want to use to open this file" (in Windows 7, presumably in most Windows OS's).

Is it possible to suppress this window?

My initial thought was to check if the extension exists in the %PATHEXT% variable before attempting to open the file. However, this does not contain all known file extensions. For example, though the .py extension is not in my %PATHEXT% variable, Python scripts are still opened correctly.

Upvotes: 0

Views: 126

Answers (2)

Ken White
Ken White

Reputation: 125767

An alternative to a direct registry query (as suggested by @Mitch) is to use the command line utility assoc

assoc .nope

If there is no application registered for the file extension it produces

C:\>assoc .nope
File association not found for extension .nope

If an association is found (for instance, for the .docx extension), it produces

C:\>assoc .docx
.docx=Word.Document.12

You might also find ftype useful. It returns the command line for the file type returned by assoc (I have Office installed in a non-default location, as you can see):

C:\>ftype Word.Document.12
Word.Document.12="D:\Microsoft Office\Office12\WINWORD.EXE" /n /dde

Upvotes: 3

Mitch
Mitch

Reputation: 22311

File types are registered in HKCR\ (full documentation available from MSDN). You can find out if a type is registered by checking for the existence of the key. In a batch file, you could use the reg command to do so.

reg query HKCR\.txt || echo This will never print
reg query HKCR\.foobartxt || echo Could not find foobartxt

That being said, file types can be defined and named without having a default handler. Further, those which have default handlers may not have command lines - the file may be launched via DDE or COM.

Upvotes: 2

Related Questions