How can I determine whether a specific file opens in windows and then closed - windows

I am working on windows 7 64 bit machine.
How can I get list of files opened. Also, the list should change when a particular file is closed.
How to get a file close event:
when file is opened in a new process of file opener (like notepad,
wordpad which opens file everytime in new process of wordpad)
when file is opened in a tab of file opener (like notepad++, which opens all files in new tab but there exist only a single process of notepad++ running).
I tried with Process Explorer, Handle, Unlocker, openfiles, not able to catch the file close event on notepad++.

Use SysInternals' ProcessMonitor.
It records all file and registry opens/reads/writes/closes. You can filter it to include or exclude specific patterns, file paths, programs, etc.
Edit
Process Monitor showing CloseFile when I close a tab in NotePad++:

Related

Open folder on portable device with batch file

General goal: create a desktop shortcut to a folder buried the file structure of my phone's SD card (connected via USB). Note, this is on a work computer, so I can't do anything to crazy.
I tried using normal shortcuts to no avail, so I decided to try using a batch if I can't use a shortcut. If using a shortcut is possible or there is a better option than a batch let me know.
Specific question: How can I open a folder using a batch file? I can manually open explorer, paste the address into the bar and go there, so there should be a way to mimic this, but so far my attempts have been unsuccessful.
Attempts:
%SystemRoot%\explorer.exe "Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch\"
explorer Computer/My S4/Phone/Android/data/com.dropbox.android/files/scratch
start "" "Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch\"
start Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch
This is an addition to Andry's answer:
It can be very complicated to get the whole path to an MTP folder like
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}
To get the path do the following:
In Windows Explorer select the folder on the MTP device you want to get the path of.
Open it's context menu and select Copy
Open in Explorer a folder on your PC, open the context menu on a free area and select Paste Shortcut
Now we need a too that can read .lnk files. I have used the tool LECmd. Execute LECmd.exe -f <path to the .lnk file created in step 3>.
You will get a lot of content printed to the console. The interesting part is the Parsing Path next to the end.
In my case it was ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\SID-{10001,,21003612160}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}
Now we are close, unfortunately the path shown above can not be used because it contains an invalid part: \SID-{10001,,21003612160}. Remove that part and you can open the explorer in that MTP folder using
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}"
There is a way to open an MTP device folder directly in the Windows Explorer window on Windows 7 x64.
Here is steps:
Open Windows Explorer with the My Computer folder, for example:
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
start "" "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
explorer "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
explorer "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
The complete list of GUIDs you can find on the internet, for example: https://www.tenforums.com/tutorials/3123-clsid-key-guid-shortcuts-list-windows-10-a.html
Attach the MTP device and enable File Transfer mode in the device. It must be shown in the My Computer window as a portable device entry.
Drag and Drop the MTP device entry icon to the Desktop.
Open any notepad, for the instance, Windows notepad: Win+R -> notepad
Drag and drop the desktop icon into notepad window.
At the end of the notepad text would be something like:
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33} (spaces removed).
You can cleanup the spaces between characters by copy the string into another instance of the notepad and replace them through the Ctrl+H to nothing.
Now you can open the MTP device folder directly:
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\<your-local-path-to-folder>"
There is a wait timeout, so the Windows Explorer window might not open immediately.
To generate a shortcut to target folder you can use make_shortcut.vbs script from here: https://github.com/andry81/contools/tree/HEAD/Scripts/Tools/ToolAdaptors/vbs/
For example:
>
make_shortcut.vbs myphonecamera.lnk "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\SD-card Samsung\DCIM\Camera
Now you can click myphonecamera.lnk to open the folder or use the Windows Explorer:
>
explorer myphonecamera.lnk
Instead of using Computer which is not a device name, try to use \\?\ or \\.\ which both refer to the local computer.

Windows Explorer and Reparse Point Files: keep Explorer from opening my files

I've implemented a user mode program and a Windows file system minifilter that creates a skeleton view of users files for a remote file storage system. It maps the remote files to the local drive. The user mode program creates a reparse tag for each file on the remote system. When a create request (e.g., CreateFile for read) is detected, the minifilter asks the user mode program to download the file. This should only happen when a program wants to open the file for viewing or editing.
But, I'm finding that Windows Explorer is triggering my files to download. I'd like to prevent the Explorer File windows and File Open/Save dialogs from
triggering downloads. And, I also want to display the file thumbnails and file
size.
[Update: I've found I can use Windows sparse files to show my remote
file size in Explorer. ]
Therefore, I have also implemented a Shell Extension, IThumbnailProvider, that downloads a rendition of the file. This provides the file thumbnails.
For my testing, I've registered the IThumbnailProvider for all files (*) and for .jpg files.
I'm seeing two interesting behaviors using a combination of Process Monitor and DebugView (both from SysInternals):
1. If I make my minifilter reject requests to open the file from Explorer, then my IThumbnailProvider is invoked.
2. If I permit open requests from Explorer, I see thumbcache.dll in the call stack trying to open the file and my IThumbnailProvider is not called. It appears that the default thumbnail provider reads the downloaded file and creates the thumbnail.
I must be missing something.
Update: if I use InitializeWithStream instead of InitializeWithFile, it appears my handler is invoked. But, that also triggers a download of the file.
There are many shell extension types which can access to your files. Icon handler can read file to create icon, Info tip handler can read file to create text hint, Data object handler can read file to create clipboard data and so on.
Questions from developer with the same problem: first and second. Solution was to create namespace shell extension. NSE can control all access to your files.

Automate a manual process of opening / saving as files

I have a tool which opens .HED files which are some kind of documents created a long time ago..
This type of files is so old and tools opening this extensions are rare. fortunately, I have a tool which opens them. when opened this program gives the choice to open files and saving them as other extensions (.rtf for example )
The problem is: there are about 400 files to be converted from .rtf to .hed and we went to automate this process of opening .rtf file saving it as .hed by some command line.
Is there a way to do so in Windows?
I'm able to open the program by "open 'program_name'" but I'm wondering if it's possible to open all files in folder and saving them as .hed after
Thank you

Open an already opened (by others) Excel file with BATCH

I have a BATCH code, which perfectly opens an EXCEL file:
START "C:\office\excel.exe" "C:\tmp\file.xlsx"
BUT: If someone else opens this EXCEL file (via network) and do not close it --> he leaves it opened, then I cannot open this file using my BATCH.
If I click on the EXCEL file, and press ENTER (so opening using windows not batch), the file will be opened, but it alerts me that someone else is locked this file, but I can open it to read or I can request a notice if the other person closes the file.
How could I set in BATCH file, to open the EXCEL (or WORD) file (only for reading) even if it is opened by others (via network)?
The solution is: leave the START command:
"C:\office\excel.exe" "C:\tmp\file.xlsx"

Windows SaveAs dlg with OFN_OVERWRITEPROMPT doesn't detect file deletions?

I'm using a perfectly usual SaveAs dialog (in Delphi Win32 XE2, the system is Win 7 /64), setting OFN_OVERWRITEPROMPT (or the Delphi wrapper's equivalent dlgSave.Options := [ofPathMustExist, ofOverwritePrompt];. So if I select an existing file, the dialog asks for confirmation to overwrite the file.
Everything works as it should except for one silly thing: when I choose a file, then delete that file right in the same dialog, then press OK, the dialog still asks if it's ok to overwrite the (already deleted) file. Apparently, the dialog checks file existence against a pre-loaded list, not the file system. The problem is not specific to Delphi and can be shown very easily even in Notepad:
Run Notepad.exe
Enter some text
Save as a file
Click File Save As again, in the SaveAs dialog do:
Click on the same file to select it,
Right-click and delete the file,
click OK.
The file is no longer there, but you still get the overwrite prompt.
Can anybody please suggest a way to work around this minor but annoying Windows bug? I assume some message processing / callbacks / hooks might be required? A way of checking the file presence in code while the modal SaveAs dialog is open?

Resources