When a Windows batch file is launched via a shortcut (from the Start Menu, for example), its window will typically receive the title of the shortcut.
Is it possible for the batch file to determine the name of its own window?
This question is related to Can a Windows batch file determine its own file name?, but that question asks if the batch file can determine its own filename. I am asking if a batch file can determine its own window name.
StackOverflow user QcFe lent a kind hand by finding this QA on Superuser: https://superuser.com/questions/1155853/how-to-get-the-window-title-text-from-batch-file
The short answer is that Windows provides no simple and direct way for batch files to accomplish this task.
Windows provides the internal title command to set the window title, but no way to retrieve it. (Which is disappointing, because it would be such a simple addition to the title command.)
The functionality can be attained using PowerShell or possibly tasklist, but for the latter, there are issues that need to be addressed if there are more than one command shell window open.
I elected to force the window to have a unique name using the Title command. That way I could reference it correctly for tools that need to know the window title, such as NirSoft's excellent nircmd utility.
Related
I need to open the file using Windows 10 cmd. But when the file opens, I need Windows to show me a modal window "How do you want to open this file?". The system should do this even if it already has a program selected by default to open a certain type of file. Is it possible to do this?
To clarify my problem:
I need the console to run for example ".py" not through the standard Python.File="C:\Windows\py.exe " "%L" %*, and for example via VS Code. You might tell me about the VS Code CLI. But how to handle an event where the user will not have VS Code, but for example Pycharm, and the user will want to open it through it? That is why the question was posed in such a way that the user could choose through what to open the file already through the built-in modal window in Windows. In any case, I will be glad of any suggestion to solve my problem.
I tried to find something similar, but apart from the standard start something.som I didn't find it. And this is not a solution to the problem, because start starts the file in the program that is specified by default in the system. This program may not even be the one that the user ever chose later. I came across a similar question in Stackoverflow, where a person wanted to see which program was responsible for opening a file with a certain extension, where assoc and ftype were used, but they did not give the desired result.
Context
I have a Windows app printing PDF files by forwarding the file paths to ShellExecuteEx and the verb print. Adobe Reader is installed and registered for that verb. Reader by default creates a LNK shortcut file in the start menu:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Adobe Acrobat DC.lnk
Hide windows
By default, reader shows a GUI window when printing a PDF. Some customer doesn't want that window and simply tried to "hide" it by changing the LNK file content using Windows Explorer properties to at least minimize the windows by default. That customer didn't know if that works or not, one simply tried.
To my surprise this worked, changing the minimize vs. non-minimize/default setting of the LNK file made the reader windows being visible or minimized.
No changes in registry
I've searched the registry for changed settings regarding the print verb, but couldn't find any. The new setting really seemed to be only stored within the LNK file:
The registry contained references to the actual EXE only, not the LNK file. Pretty much like expected, I've never came across any shell verb registration using LNK files at all.
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /p /h "%1"
Though, all invocations of the verb print seemed to recognize that setting, either manually using the context menu of some PDF in Windows Explorer or executing things on the shell:
powershell -Command "Start-Process -Verb print '\\?\C:\[...].pdf'"
Why is that important?
Adobe Reader provides the command line argument /h to minimize itself as well, but using that doesn't fully hide a window at all. Instead, a window is shown for a second or so and afterwards minimized, e.g. like Adobe is doing that itself. OTOH, with the changed LNK file things are different: Either really now window is shown at all or only some artifacts like the window title or alike for less than a second.
It really seems that the difference is between Adobe doing something on it own after it has loaded and stuff vs. Windows itself creating the minimized window already.
Additionally, if possible at all I would like to avoid customers needing to change the LNK file themself. The problem with that change is that it's not tied to the print verb only, but whenever Adobe Reader gets opened. And sometimes customers really need to have a look at PDFs themself instead of automatic printing only.
So, how does that work?
Is Windows itself using the setting of that LNK file or is this something implemented by Adobe Reader?
Using ProcMon, I couldn't find any hint about that Adobe Reader itself reads the LNK file. As well, I couldn't find this behaviour documented in the topics about shell verbs, ShellExecuteEx etc. It's totally unexpected to me, as the LNK file is some arbitrary file in theory, which might not exist at all, can be named as one likes, even multiple of those could exist in theory starting different apps of some package or the same app with different arguments etc.
Thanks for any insights.
Not sure whether I have the message above exactly correct but I run into this often. I try to use Windows to delete a directory or a file and it tells me I can't because the file is in use by another program. It doesn't say what process is using it.
Sometimes it is clear what is using it, but other times it is not. I open the Task manager and go through all the processes but nothing stands out.
Is there a way to determine what has a file open, and a solution (other than rebooting)?
I suppose most of the time it may be Eclipse related but certainly not all of the time.
I use Process Explorer
Ever wondered which program has a particular file or directory open?
Now you can find out. Process Explorer shows you information about
which handles and DLLs processes have opened or loaded.
You can add the column like shown below (Window Title) and it should help you find the file you are looking for, and what is using it:
If you end up choosing to use this program instead of Task Manager, there is an option for that which will open this instead of Task Manager:
If you decide to "Replace Task Manager" and ever get stuck where you cannot 'undo' what you've done (Meaning, "The original Task Manager will no longer open")... You can modify the registry listed here and delete the Debugger entry. (In this example, I have this path to a network drive).
I had this problem in Excel, where some files would be active, but not visible to me, either on my screen or in the task manager. The way I solved it was to use the command prompt to kill the task:
Open command prompt (type cmd in windows search at the bottom left of your screen)
Type "tasklist"
Find the task you want to terminate (for me it was EXCEL.EXE)
End the task by either using the image name (type "taskkill /im EXCEL.EXE", or whatever program you want to end. This will kill all tasks with that image name) or using the ID (i.e. "taskill /pid 1234, or whatever ID the program has. This will kill that specific task)
I have written a Windows software and I have associated a file extension with this program. When I double click a data file then my program starts up and opens the file. So far it works. But when I select multiple files and then click "Open" in the context menu then multiple instances of my program are started, one instance for one file. I want Windows to open ALL files with a single instance of my program. Is this possible without implementing a one-instance-handler in my program?
Currently the MyFileType/shell/open/command in the registry looks like this:
"C:\Program Files\MyApp\MyApp.exe" "%1"
Maybe there is some special Token/Variable I have to use instead of the "%1" to get it working? On Linux I have to use %f for a single file and %F for a list of files. Is there something similar on Windows?
The simplest way is to associate your app with the default shell verb (e.g. “open,” or “play,”) for the file type, and implements a drop target that uses SHCreateShellItemArrayFromDataObject to get the selected files. Suggested reading: How the Shell Invokes Verbs
If you don't like to take over the default verb, you can add your verb to the file association's open with list.
Another method is to make your app a singleton and send the document's path to the first instance via inter-process communication methods such as DDE or RPC. This requires you to keep your main window responsive (for example, won't work if you are showing a dialog)
%* might be what you're looking for.
I have a batch script under Windows. When anyone will click on that script I want the command window to become full screen like we do by keyboard shortcut [Alt+Enter].
Can it be done automatically using any command in batch file?
In Windows XP, you need to start your program maximized (but not full screen) via "start /max" as follows:
start "Winow Title" /MAX "C:\batches\myfile.bat"
This command would be inside your original batch file, and call the real bath file.
I don't think there's a way to change the full screen-ness of an executing "cmd" command from within a batch file absent someone writing a special app to do so by emulating sending Alt+Enter to the parent process.
In Windows 7 (and probably Vista) you must run inside XP virtual machine for full screen mode.
There is none. You can write a small program doing so for you, though. There is the SetConsoleDisplayMode function.