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"
Related
This is the scenario:
I'm using ShellExecuteEx in order to open a given .xlsx file. This works fine, Excel is started and the .xlsx file is opened in Excel.
Now ShellExecuteEx is returning more or less instantly before even Excel has fully started and opened the .xlsx file. So far so good.
Is there a way to wait until the .xlsx file has been actually opened by Excel? Something like a BOOL FileIsOpenExclusively(LPCTSTR filename) function which returns TRUE is the file is opened exclusively?
Then I could do somehing like this (minimalistic, naïve and non error checking) pseudocode:
ShellExecuteEx(... stuff for opening myfile.xlsx ...);
while (FileIsOpenExclusively("myfile.xlsx"))
{
Sleep(500);
}
// now "myfile.xlsx" is opened execusively
EDITED
The actual slightly more complicated scenario is this:
ShellExecuteEx launches Excel open the given .xlsx file.
then I need to know somehow when the .xlsx file is closed, either because the file is closed by the Excel user or because the user quits Excel alltogether.
What I'm doing now is illustrated by this pseudo code:
ShellExecuteEx(... stuff for opening myfile.xlsx ...);
Sleep(5000); // wait that Excel has hopefully has opened the file
do
{
Sleep(500);
Open("myfile.xlsx");
} while (opening file is unsuccessful)
// file could be opened which means that Excel has closed it
Close("myfile.xlsx");
The problem is the Sleep(5000);: if Excel could not open the file within 5.5 seconds, the test below will fail because it will think Excel has closed the file even before it was opened. Therefore I need to know when Excel opens the file rather than waiting a determined amount of time.
Maybe there is another approach. Some comments have suggested to use WaitForInputIdle which sounds promising, but this may not work if there is already an open instance of Excel beforehand (to be tested).
Another comment suggested enumerating the top-level windows and check for changements of the window title, but I'm not sure this works with modern Excel versions (to be checked) and if it works, it may stop working with the next major Excel version.
Using an oportunistic lock sounds very promising, I'll test this next week.
And finally using the Restart manager might be a lead as well.
As others said, there is no way to know when an app opens a file, but if it is specifically for Excel you can use COM automation.
Here is a python example, here is the generic documentation. In C++ you have to use CoCreateInstance to acquire an IDispatch.
What is the way of saving open .txt file in autohotkey. Let say you have opened text file test.txt; and you would like to close it or close it with saving any edits that you have made to that file.
I'm unable to find any method on the internet/doc. It can be a simple #1:: hotkey. It's part of larger script and this is just for testing.
Thanks xDD
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
I'm aiming to open a new .txt file in Notepad and then write to it. Since the file I'm opening (notepad.exe) isn't the same file I want to write to (the new .txt file), I'm unaware of how I can write to the file. Here's the code I have so far:
local list = io.popen("notepad.exe","w")
print(list)
list:write("Tester")
list:flush()
Notepad is opened, but the text isn't written to the new file because the code is trying to edit notepad.exe instead.
What can I do to be able to edit the new opened .txt file? I don't want to actually save the file anywhere, so that's why I'm aiming to just put text in an untitled .txt file. Thanks in advance :)
Notepad does not respond console input.
You must find edit control on notepad's window and PostMessage keypressing event to it.
Or prepare temporary file and load it:
local list = io.open("newfile.txt","w")
list:write("Tester")
list:close()
os.execute("notepad.exe newfile.txt")
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++: