Jump to content

I want to learn how the process of opening a text file through double click works by making a script


Go to solution Solved by Dan_555,

Recommended Posts

This seems like a fun bit of tech knowledge that I don't have but will find useful.
So, from start to finish, what happens when you double click a text file and it opens in Notepad? How do we change that in the registry?
On the script side, how to we catch and parse the filename to a string? Is it a string from the start?

Like I said, this isn't with the goal of designing one script. Rather, it's a skill that I want to pick up to use in projects going forward. 

Thanks for your time!

Edited by Draygoes
Spelling
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites
  • Solution
Posted (edited)

Windows is treating the filenames as Strings.

The filename (argument) is passed to other apps as  a string. 

On the AutoIt Script side, it is passed as a string as well, see the Command Line Parameters: https://www.autoitscript.com/autoit3/docs/intro/running.htm

 

When you double click on a text file, on windows side, it can be a bit complicated.

I do not know the exact order but it looks something like:

Windows explorer is checking if the text extension, usually ".txt" has an assigned app to open it.

If yes, it is opening the default app, if no, it is looking first if there is an app for the unknown files ( * ), then if it does not know how to, it presents a list of apps which could open it.

(The apps usually set the extensions which they can open, somewhere in the registry (new in win 10 i think) )

 

Here is a small info on how to change the default editor for .bat files:

https://www.itprotoday.com/windows-78/how-can-i-change-default-editor-used-editing-batch-files

 

They use, in the example:

Quote

D:\Program Files\Microsoft Office\Office\winword.exe %1

But i remember, at least from the XP times that the filenames/paths with spaces in it may not work. (because space is a delimiter char, used to distinguish the program from the parameter)

The correct use, at least for windows before 10, should be:

Quote

"D:\Program Files\Microsoft Office\Office\winword.exe" "%1"

 

Edited by Dan_555
Link to post
Share on other sites

In Windows 10 it normally uses the following key, you would need to find the hash key which is machine specific which can be a challenge although their are tools from memory that can automate this.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice

While you can use group policy to force file associations, it means users aren't able to change those associations

https://admx.help/?Category=Windows_10_2016&Policy=Microsoft.Policies.WindowsExplorer::DefaultAssociationsConfiguration

You can configure the default user file associations, but this only impacts new user accounts not existing user accounts.

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/export-or-import-default-application-associations

Link to post
Share on other sites

Why can't I remember how to insert multiquotes?

Old Fashioned way it is.

@Dan_555Thanks for the details! I'll post a working example when I get around to actually using this. :)
@SubzLove that name btw; So if it's that complicated, how does every other program manage to pull it off? Most programs for editing anything registers it's own file type.

Thanks for the responses guys.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites

Also, is drag and drop treated like an open command? Does it just pass file location when you do that as well?
(I'm not able to test at the moment)

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites

TBH, i do not know how the windows explorer is handling the drag'n'drop.

I'm using the FreeCommanderXE, and here the drag'n'drop works very well with autoit scripts, while the windows (10) explorer does not. 

The full path+filename is passed to the script. 

 

Link to post
Share on other sites

thats because FreeCommanderXE is Win32 based exe, Explorer is now way different and doesn't use win32 controls. If you want to automate Windows Explorer then you must learn UIAutomation

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to post
Share on other sites

i would not expect it to work like win32 based systems at all, even with dragon drop

best off to start reading this

https://docs.microsoft.com/en-us/windows/win32/shell/dragdrop

you should be able to use the clipboard as mentioned in the docs sp with AutoIt you can use Objects like the IDataObject

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...