WMIC open file or URL - windows

Using cmd.exe, you can open a file or URL in the user’s preferred application.
start example.txt
start http://example.com
I see that WMIC can start a program
wmic process call create notepad.exe
However, can it open a file or URL, like start?
Start - Windows CMD

This won't open the 'favored' browser, but you can get to a browser without the need for start.
wmic process call create "C:\Program Files\Internet Explorer\iexplore.exe www.google.com"

wmic process call create "cmd /c start http://example.com"
start is an internal command of cmd.exe, so, you need to execute cmd.exe to reach start command

Related

close all open folders in file explorer using batch

I want to create a bat file that can close all open folders in the file explorer. However, it should not close any programs that are open (for example: excel, outlook, web browsers etc). Any help would be appreciated!
Thanks!
You could use wmic to find all explorer.exe processes with -Embedding in their command line and terminate those. This should skip the shell since it doesn't have -Embedding in its command line.
wmic Path win32_process Where "CommandLine Like '%\\explorer.exe % -Embedding'" Call Terminate
As Compo pointed out in the comments: For this to work in a batch file, you need to double the percent signs:
wmic Path win32_process Where "CommandLine Like '%%\\explorer.exe %% -Embedding'" Call Terminate

Keep cmd.exe console window with specific title open?

in Windows 7 x64 SP1 I need to create a batch file (.bat) which keeps the cmd.exe console window open and has a specific title:
#ECHO OFF
title notepadtest
#ECHO ON
start "" /WAIT notepad
But this batch file keeps opening an infinite number of cmd.exe console windows in an unstoppable loop!
How can I create a batch file (.bat) which creates only ONE cmd.exe console window and keeps it open and has a specific title?
Please ensure that your batchfile is not named notepad.cmd or notepad.bat or anything like any system or external command. Name it something like mynotepad.cmd instead., then try this one please:
#echo off
title notepadtest
start "" /w notepad.exe
cmdline and batch files typically works like this. When a command is issued, it first checks the local path, where the script was launched from for the command, if not found, it will check your environment and system environment. So if you name a batchfile notepad.bat your batch is actually starting itself over and over, instead of finding notepad.exe in the environment variables.
Always name batch files something unique and not system/external command related.
Always use full executable name in a batch, like start "" /w notepad.exe and not start "" /w notepad

How to hide command prompt windows using ExecDos command

I want to execute three bat files in my script, the problem is when i run these .bat files directly using execwait, command windows gets open, I want to hide these command windows but its not working. My code is of just 3 lines.
ExecDos::exec '"catalina_start.bat"'
ExecDos::exec '"mysql_start.bat"'
ExecDos::exec '"apache_start.bat"'
I also tried this nsExec command but still no solution:
nsExec::Exec "cmd /C catalina_start.bat"
nsExec::Exec "cmd /C mysql_start.bat"
nsExec::Exec "cmd /C apache_start.bat"
A little background on these .bat files, Actually these are files of xampp setup, xampp internally uses these files to start tomcat, mysql, and apache.
The problem I am facing is that only first bat file gets executed, i. e. tomcat gets started (I can see that in xampp console), but then script dosen't move ahead, sql and apache is not getting started.
Does the batch-file contain pause or something else that prevents it from completing?
You should start off just by using something like ExecWait '"cmd.exe" /k "$InstDir\catalina_start.bat"' (or /c) so you can see the text written to the console including any errors. Once it works correctly you can switch to one of the exec plugins that hides the console...
You can change command windows from cmd /C catalina_start.bat to start /Min cmd /c catalina_start.bat it will hide command windows

Run a .cmd file through PowerShell

I am trying to run a .cmd file on a remote server with PowerShell.
In my .ps1 script I have tried this:
C:\MyDirectory\MyCommand.cmd
It results in this error:
C:\MyDirectory\MyCommand.cmd is not recognized as the name of a cmdlet,
function, script file, or operable program.
And this
Invoke-Command C:\MyDirectory\MyCommand.cmd
results in this error:
Invoke-Command : Parameter set cannot be resolved using the specified named
parameters.
I do not need to pass any parameters to the PowerShell script. What is the correct syntax that I am looking for?
Invoke-Item will look up the default handler for the file type and tell it to run it.
It's basically the same as double-clicking the file in Explorer, or using start.exe.
Go to C:\MyDirectory and try this:
.\MyCommand.cmd
Try invoking cmd /c C:\MyDirectory\MyCommand.cmd – that should work.
To run or convert batch files to PowerShell (particularly if you wish to sign all your scheduled task scripts with a certificate) I simply create a PowerShell script, for example, deletefolders.ps1.
Input the following into the script:
cmd.exe /c "rd /s /q C:\#TEMP\test1"
cmd.exe /c "rd /s /q C:\#TEMP\test2"
cmd.exe /c "rd /s /q C:\#TEMP\test3"
*Each command needs to be put on a new line, calling cmd.exe again.
This script can now be signed and run from PowerShell outputting the commands to command prompt / cmd directly.
It is a much safer way than running batch files!
First you can reach till that folder:
cd 'C:\MyDirectory'
and then use:
./MyCommand.cmd

Hide CMD window after using START to run a network application

I have an application that is run over a network. I need to be able to run this application from a batch file, and had ended up using this:
pushd \\server\folder
start /wait program.exe
Aside from the message saying...
\\server\folder
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
...it works fine, but the CMD window lingers. I know that /wait is the cause, but it appears that I can only get the program to run successfully if I use /wait. If I remove /wait, then I get bizarre errors from the program about not being able to start successfully.
What else might there be that I can try?
If you want to hide the program while it runs, you can also use the /MIN param, to have it start minimized.
Try:
start /b /wait program.exe

Resources