batch script--List of active programs via command prompt - batch-file

How to find active programs through windows command line?
By active program, I mean any program that the user is using or just kept minimised. Not all running programs/processes we get when we type "tasklist".
eg: If I close google chrome, It still shows in the tasklist. But They are background processes. I don't want to list that process.

Can you use PowerShell?
If so, you could use the line below to get all the processes that don't have a window title.
It may not catch everything you want though.
Get-Process | Where {$_.MainWindowTitle -ne ''}

Related

Trying to start multiple .exe files in order with a bat file but first line fails and second line is successful

My code in the .bat looks like this.
"C:\users\reshade injector.exe"
C:\pathtogame\game.exe "added argument"
"c:\users\reshade injector.exe" <- if I open the actual file, it opens a command window and waits for my other application to launch. Is this a console app?
C:\pathtogame\game.exe "added argument" <- this works and launches my game
Another issue is that when launching the first .exe, a command window stays open. How do I make the command window not appear?
Can anyone help me with these two problems?
*edit for clarity
by opening the actual file, I mean double-clicking on the original reshade injector.exe.
When opening reshade injector.exe, two cmd windows open. They close as soon as I launch the game.exe.
I can't seem to get the reshade injector.exe to launch through the .bat file.
Batch will run any application it finds. If the application does not terminate (eg. it's waiting for user-input) then it will progress to the next instruction.
Some applications work by launching another (the user-interface) and then terminating, leaving the second application resident.
There's no way to tell without observing which approach any random application may take.
So - your batch should execute a file named c:\users\reshade injector.exe.
You say that "fails". Is there an error message generated? You would likely need to run the batch from the "command prompt" to see that message. Note that the Space between reshade and injector must be in the actual filename. If injector.exe is a file in a subdirectory called reshade, then you need a backslash between reshade and injector.
Having resolved the actual name of the first executable, try
#echo off
setlocal
start "" "firstexecutablename"
start "" "secondexecutablename" "arguments"
The first two lines prevent "command echoing" which is used for debugging and establish a "local environment" which ensures the "environment" for the batch file remains unchanged when the batch terminates. In the current case, these two lines are probably unnecessary, but it's SOP for batch files.
The batch should then close its session and window once it has attempted to launch the two applications.
The "" following start becomes the window-title. It can be any quoted string you like, but should not be omitted as start uses the first quoted string it finds as a window-title and may not recognise it as part of the executable/arguments.

run wordpad print and delete tempfile in progress 4gl?

I have a rtf file with data and now I have created a temp file and batch file . Now how do I run wordpad print and delete tempfile in progress 4gl
you can use the write.exe command line options:
write.exe /pt someFile.rtf "Microsoft XPS Document Writer"
Here the "Microsoft XPS Document Writer" printer is used. You can list available printers with powershell "get-WmiObject -class Win32_printer | ft name, systemName, shareName"
You use the OS-COMMAND method. You can do that to invoke any os-command in any supported OS.
OS-COMMAND [option] VALUE("whatever command you like to run").
There are three different options
SILENT
After processing an operating system command, the AVM shell pauses. To exit the window in Windows GUI platforms, you must type exit. To exit the window in Windows character platforms, you must type exit and press RETURN or SPACEBAR. You can use the SILENT option to eliminate this pause. Use this option only if you are sure that the program, command, or batch file does not generate any output to the screen. Cannot be used with NO-WAIT.
NO-WAIT In a multi-tasking environment, causes the AVM to immediately pass control back to next statement after the OS-COMMAND without waiting for the operating system command to terminate. Cannot be used with SILENT. This option is supported in Windows only.
NO-CONSOLE While processing an operating system command, the AVM creates a console window. The console window may not be cleaned up after the command is executed. You can use the NO-CONSOLE option to prevent this window from being created in the first place.

Open multiple Microsoft Edge windows from batch file

I need to open 2 Edge windows from a batch file (not two tabs, 2 windows). I know I can launch edge using the following command:
start microsoft-edge:
But if I try it twice the second command does nothing. If I try it with URLs I get 2 tabs in the same window. e.g.
start microsoft-edge:http://google.com
start microsoft-edge:http://bing.com
Any ideas how to get 2 separate windows?
Use --new-window option:
start msedge http://google.com
start msedge --new-window http://bing.com
As you are aware, you can trigger Microsoft Edge indirectly from the command line (or a batch file) by using the microsoft-edge: protocol handler. Unfortunately, this approach doesn't enable you to open up an arbitrary number of windows.
The Microsoft Edge team built a small utility to assist, and presently hosts it on GitHub.
> MicrosoftEdgeLauncher.exe http://bing.com
> MicrosoftEdgeLauncher.exe http://stackoverflow.com
I just tested this, and it opened two individual windows for me. There does appear to be an issue where the second window doesn't navigate to the URL; remaining open with the New Tab Page.
You can open as many as you like, just create batch files that call other batch files.
Very easy to do.
Ex: batch1.cmd:
#echo off
start microsoft-edge:http://google.com
start "path\batch2.cmd"
exit
Make sure to add "start microsoft-edge:http://bing.com" on your "batch2.cmd" file
Manny
You can use the executable msedge_proxy.exe which is installed alongside msedge.exe. For example in "C:\Program Files (x86)\Microsoft\Edge\Application".
Sample usage:
> msedge_proxy.exe --app=http://bing.com
If you execute that command multiple times, it pops a new window each time.

Spawning multiple copies of a program from C code and redirecting the output to a file

I am working on modifying a command-line program that is written in MSDN C and Pro*C (Oracle pre-compiler to write in-line SQL and PL/SQL statements) so that multiple copies can be spawned and process concurrently. It is a database-heavy program and concurrency issues are mostly taken care of on the database side, so we thought it would be easier to just run multiple copies than to alter the program to run truly multi-threaded.
Anyway, we rely on printf() and output piping to write the program's output to log files for debugging purposes. I am having trouble launching separate copies of the exe that appropriately write to their own log files. I have played a lot the exec() and system() functions to get different copies of the EXE to launch and write to logs. The closest I have gotten to work is using a C line such as:
system("start cmd /k call [program commmand and args] > log_file.txt");
This works great - spawns separate command windows and spawns separate copies of the program for the appropriate data-sets. The only problem is that the command windows stay open after the program has finished executing. Some of our clients run this program frequently on a scheduler, and having to manually close all of the command windows would not be acceptable for them.
Other similar commands that I have tried to get to what I am looking for are like:
system("[program command and args] > log_file.txt");
or
exec("[program command and args] > log_file.txt");
Both of these will execute a new copy of the program, write to the log files just fine, and close the command window when the process is finished, but the commands wait for the newly spawned EXE to finish running to return control to the launching executable. This obviously prevents multiple copies from running at the same time, which was the whole goal to begin with, so this is not a good solution either.
I also played with trying to add an "exit" command to the end of the command line windows by appending to the exiting command line, hoping that I could get the command window to close, like this:
system("start cmd /k call \"[program commmand and args] > log_file.txt; exit\"");
to no avail. I tried some similar variations, but could never the correct behavior.
I would greatly appreciate any advice that could get the correct behavior. I am basically looking to launch multiple copies of an executable that run concurrently and write to separate log files, using the " > log_file.txt" output-piping feature of the windows command prompt. I would like to avoid having to use threading libraries (It's been awhile and I'm under time constraints) or using something other than printf() and output piping, since these print statements are used throughout the application and it would be a large effort to effectively replace all of the function calls at this point in time.
Anyone know a way to get the command windows to close using system() calls, or have some other easy method of solving the problem? Keep in mind that there are some time constraints involved, so I'm not necessarily looking for the best way to do this, but the quickest and easiest. I will have the opportunity to implement proper logging functionality soon, but I need to get past this problem first.
You said your first solution works great except it doesn't close the command window after the program is done executing.
system("start cmd /k call [program commmand and args] > log_file.txt");
The /K option states Carries out the command specified by string but remains
The /C option states Carries out the command specified by string and then terminates
You should be able to change your original solution to use the /C option as so
system("start cmd /C call [program commmand and args] > log_file.txt");

How do i specify to start an application in the specified process?

How to specify to start an application in the specified process in command line.I mean let us take a look at the below command
start "cool.mp3"
it opens the file cool.mp3 in the windows media player but i want it to be opened in the VLC player.How do i mention it?How do i tell to open the file in the VLC player or some other real player.Can we mention the application to run in the specified process ? If so how?
start uses the file associations set by the user. If you want a specific program, then just do so:
"%ProgramFiles%\VideoLAN\VLC\vlc.exe" cool.mp3
Also note that the example you gave can never work with start anyway.

Resources