Win CLI open file with "How to open"? - windows

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.

Related

How to implement "open with" in a notepad application

Getting straight to the point, I am basically creating a clone of notepad in java and I want to implement this functionality:
Assume I have a file like this with the .txt exention
I procede to right click and select the open with option, where notepad and vscode are also present
What I want is for my application to be here, and I know that I have to edit the registry and add the main executable of my app for every text file associations and I'm pretty confident I can do it with by running the reg command in batch (correct me if I'm wrong).
The part where my personal research was not good enough is actually how to physically implement the open with behavior in my java code, meaning I don't have any "entry points". If only I had the path of the selected file I could call my open() function with that path and the job would be done. However, I don't understand what's going on in the background.
Note: I am still learning batch and windows related topics so I apologize if this is a stupid question

Can a Windows batch file determine its own window name?

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.

How to call a function when opening program from file?

I made a project in visual studio 2010 (maybe a bit outdated but I like it this way).
With that project I made a separate project that handles the setup file for the installation. In this setup project I assigned a file type to my project so that the program can be started by double-clicking the file.
Now all of this works, the file gets a icon similar to the program and when I double-click it, the program opens. The only problem is that it doesn't open the file that was clicked.
I think I need to change something in the 'command' that is seen in the file type properties. As it is, I just have it set to "Primary output form Project 1". How can I make it so that it doesn't just open the program, but also calls a function that loads the data inside the file?
I'm sorry if this question has been asked before. I searched for it but I couldn't find a similar question. I'm also pretty new to the whole programming thing.
Thank you in advance!
You want to pass the filename to your program as a command line argument.
Add %1 to the end of the command you have associated with the file extension.
For example: "C:\path\to\MyProgram" "%1"

ActivePerl. .pl files no longer execute but open in Notepad instead

I have perl scripts which were running in Windows 7 just fine as of this morning. I made the mistake of using NotePad as the default for opening/editng my .pl files. Now, when I attempt to run the unedited .pl files from a DOS prompt, the script does not execute but opens the associated source code file in Windows Explorer. This is the same for all my .pl files no matter the complexity (including classic "hello world".
I have been researching changes need to the registry - it all looks fine. Tried assoc and ftype changes - nothing. Tried reinstalling ActivePerl - no solution.
You don't need to go into the Registry.
Go into Windows Explorer.
Find a file that ends in a *.pl suffix.
Right click on it and bring up the Context menu.
Select "Open With" (It might just be Open... with an ellipse after it. I don't have a Windows machine at the moment to verify this). This will bring up a dialog box with all the various programs. NOTE: Perl may not be listed in the initial set of programs. No worry, just navigate to it.
On the bottom of the dialog box is a checkbox (Something like open all extensions with this program). Make sure that checkbox is checked.
After this, all files that end with *.pl will open with Perl instead of Notepad.
It is highly likely that someone did this with a Perl script in order to edit it, and messed up the file association.
However, who ever did this should be doped slap -- not for messing up the file association, but for editing a program with Notepad. Bad Developer! No doughnuts for you!
Programs should be opened with a Program Editor. If you're a real he-man, you can use VIM. VIM is a fast, and powerful program editor, but you will need to spend an internship at the feet of a VIM Ninja master in order to learn how to use it. Your first three to six months with VIM will be What a idiotic program! This is awful. Who wrote this crap?. Then, one day, you will understand its power and efficiency. You will be one with the program.
If you aren't brave or fearless or don't have six months to waste learning a programming editor, you can use Notepad++. Compared to VIM Notepad++ is like driving a Minivan. It's safe, it's practical, and it gets the job done.
Both editors do Syntax Highlighting which can help you find issues. Both, (VIM can -- I think Notepad++ can too) offer help with syntax and usage. Both can edit a file without messing up the line endings (They'll both detect whether a file has Unix or Windows line endings and keep those or allow you to convert them). Both will number your lines, have extensive cut/paste buffers, powerful search and replace features. And will not mess up your file encoding. Both offer visual diffing between files and do automatic backups when you edit a file.
Finally, these two editors will embed themselves into the context menu you get when you right click on a file. You can edit a file by clicking on it, and selecting VIM or Notepad++ directly from the context menu. No need to select "Open with..." and possibly mess up the file suffix association.
Never ever use Notepad to edit a program.
Sounds like your .pl extention association is now set to Notepad rather than perl.exe. If you are too busy to fix that, just type "perl yourscript.pl" in a command promot window to start the perl interpreter and to send your script to it to run.
See this answer to fix the association:
File Type .pl Association and Using cmd.exe to Run the Script
I have the same problem. None of the method mentioned above solve the problem. The problem actually came from Windows 7! Windows 7 Doesn't allow you to associate .pl to perl.exe in c:\Perl64 directory, for whatever reason.
Here is the solution:
If you look at c:\Perl64\Bin directory (or the path where your ActivePerl binary installed), you'll see another file: Perl5.14.2.exe. This is the same file as perl.exe in same directory but with version number attached as postfix in the name.
You can associate .pl file to that Perl5.14.2.exe instead of perl.exe. Bingo, it works now.

General Question about a GUI to execute a batch file

I'm new to programming and have taken some classes in it so I'm not sure if this is possible. I want to use a COTS software called 010 Hex Editor and write a script for the program to automate a couple tasks. These tasks can be run from a batch file according to their documentation.
Then I want to instruct the user to eject the device and reinsert it to clear the cache. (This I want done just with a simple pop-up window.
Then I also want to format the device which I assume can be done in a batch file as it can be done through dos on Windows.
My question is, with these 3 steps, can I build a simple GUI that has a button that says, "Start" or something like that, then the pop up window comes up to eject and reinsert, and then another button to format, and another button to exit. I'm not really familiar with what language this could be done in, and how to do this as the C++/Java classes I've taken have been more about syntax and OOP. Thanks!
You can use the windows messenger service to put up an alert - but on newer windows (vista/7) it's a pain to set all the permissions to allow this.
There are lots of free utilities that will popup a dialog from the command line, with a given message and wait for a response.
They are generally called messagebox or msgbox - sorry can't recommend any in particular

Resources