On windows, what's the command prompt argument to 'start' that will run a second instance of a program simultaneously? - windows

This forum post
https://cycling74.com/forums/topic/running-multiple-max-applications-on-the-same-machine/#post-369180
mentions using
open -n /Applications/"max 6.1"/Max.app
to run a second instance of, in this case, Max/MSP, but this is on a Mac. What's the equivalent of -n in Windows?
I also found an old forum post
http://www.overclockers.com/forums/showthread.php/647714-How-can-you-open-multiple-instances-of-the-same-application-in-Windows
where one user suggests
...you could also create a cmd or bat file with content similar to
this:
"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe" /n "%1" or
start "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe" /n "%1"
or call "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe" /n
"%1"
It will launch a new instance each time you click open with and select
the cmd/bat file.
but that didn't seem to work for me (it will open a first instance, but does nothing after that), quite possibly because that was for Windows XP, not 10.

Related

BAT file with the option of using UP arrow to repeat command

I am troubleshooting a problem with a device keeping a Windows 10 PC awake using the powercfg -requests command. I have a BAT file containing the following so it can be run quickly via shortcut with run as admin properties:
cmd /k powercfg -requests
This works, but in addition to keeping the window open, I'd like to be able to keep sending powercfg -requests by hitting arrow up/enter when needed, as would normally happen if I opened a command prompt and typed it manually.
I've searched quite a bit here, and aside from making it repeat automatically,
I haven't found anything other than sending arrow keystrokes in a BAT file.
I did see something which implied it might be possible to print the command so it's entered at the prompt
after the command has executed, which would be fine too, but haven't had much luck.
Is this possible?
Sorry, there is not a simple way...
This works:
#if (#CodeSection == #Batch) #then
#echo off
start "" /B cmd /K
timeout /T 1
CScript //nologo //E:JScript "%~F0" "powercfg -requests{ENTER}"
goto :EOF
#end
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
For a further description on the method used, see this answer
Use PowerShell instead. You can right click on Desktop > New Shortcut and paste this then save
powershell -NoExit -Command "Add-Content -Path (Get-PSReadlineOption).HistorySavePath 'powercfg -requests'; Invoke-Expression 'powercfg -requests'"
It's better to create a new shortcut because you can set it to always run as admin although it's still possible to put it in a *.bat/*.ps1 file
You can also shorten it like this
powershell -NoE -C "$c = 'powercfg -requests'; ac (Get-PSReadlineOption).HistorySavePath $c; iex $c"
PowerShell is far more flexible and powerful than batch. It also has a persistent history so it's far more convenient to use PowerShell. You may not even need this and just press Ctrl+R to search through history for the powercfg command just like in bash/zsh

How can I check every time I have opened a specific program in my Windows 10?

I have been asked to pass a report that shows all the hours that I have opened a specific program in my Windows 10 since it was installed until today.
Is there any way to get a list or something similar with this information?
Replace the program shortcut with:
Batch program:
Open notepad.exe
Write:
#echo off
C:\Program files\your program path
for /f " delims==" %%i in (c:\windows\temp\counter.txt) do set /A temp_counter= %%i+1
echo %temp_counter% > c:\windows\temp\counter.txt
Save it as counter.bat
Replace program shortcut with path to counter.bat
To see clicks:
Open notepad.exe c:\windows\temp\counter.txt

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

Batch file to uninstall a program

I'm trying to uninstall a program EXE via batch file and am not having any success.
The uninstall string found in the registry is as follows:
C:\PROGRA~1\Kofax\Capture\ACUnInst.exe /Workstation
C:\PROGRA~1\Kofax\Capture\UNWISE.EXE /U
C:\PROGRA~1\Kofax\Capture\INSTALL.LOG
If I run that from CMD or batch it does nothing.
If I run C:\PROGRA~1\Kofax\Capture\UNWISE.EXE /U from CMD it will open up a dialog box to point to the INSTALL.LOG file and then proceed to uninstall.
At the end, it will ask me to click finish.
I need this to be silent, can you point me in the right direction? This is on XP and 7.
Every program that properly installs itself according to Microsoft's guidelines makes a registry entry in either HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall (for machine installs) or HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall (for user profile installs). Usually, the key for the program will be its GUID, or else the name of the program. Within that key will be an entry called UninstallString. This contains the command to execute to uninstall the program.
If you already know ahead of time what you will be uninstalling, it should be easy enough to just put that in your batch file. It gets tricky when you try to automate that process though. You can use the reg command to get data from the registry, but it returns a lot of text around the actual value of a given key, making it hard to use. You may want to experiment with using VBscript or PowerShell, as they have better options for getting data from the registry into a variable.
This might help you further.....
How to Create a script via batch file that will uninstall a program if it was installed on windows 7 64-bit or 32-bit
I've had the same problem and this is what I came up with.
Before you start using this method though, you might wanna look up the name of the application on WMIC using CMD so..
First you wanna do: WMIC product > C:\Users\"currentuser"\Desktop\allapps.txt
I'd recommend to output the command to an TXT file because it's really confusing to read it in the Cmd prompt, plus is easier to find the data you are looking for.
Now what you wanna do is find the actual name of the app... If you look at the code I put in, the app name says SkypeT because skype has "™" in the end of it and the command prompt can't interpretate that as it is.
After you got the app name, just put in the find in the 4th line and substitute, a few lines which contain my examples with skype...
Also you can probably creat a variable called %APP% and not worry as much, but at it's current it works just fine...
One thing to note! with me the msi /quiet command did not work, the program would not install or uninstall so I used /passive, which lets the users see what's going on.
#Echo off
CD %cd%
:VerInstall
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "SkypeT"') do (
if Errorlevel = 0 (
Echo Skype is installed! )
if Errorlevel = 1 ( Echo Skype is not installed, proceding to the installation!
Ping localhost -n 7 >nul
goto :Reinstall )
)
:Status
tasklist /nh /fi "IMAGENAME eq "APP.exe" | find ":"> nul
if errorlevel = 1 goto :force
goto :Uninstall
:Force
echo We are killing the proccess... Please do not use the application during this process!
Ping localhost -n 7 > nul
taskkill /F /FI "STATUS eq RUNNING" /IM APP* /T
echo The task was killed with success! Uninstalling...
Ping localhost -n 7 > nul
:Uninstall
cls
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "SkypeT"') do (
set %%a=%%a: =%
msiexec.exe /x %%a /passive /norestart
)
:DoWhile
cls
Tasklist /fi "IMAGENAME eq msi*" /fi "STATUS eq RUNNING" | Find ":" >nul
if errorlevel = 1 (
echo Installation in progress
Goto :DoWhile
)
echo Skype is Uninstalled
:Reinstall
msiexec.exe /i SkypeSetup.msi /passive /norestart
:reinstallLoop
Tasklist /fi "IMAGENAME eq msi*" /fi "STATUS eq RUNNING" | Find ":" >nul
if errorlevel = 1 (
echo Installation in progress
goto :reinstallLoop
)
echo Skype is installed
:end
cls
color 0A
Echo Done!
exit
One last thing. I used this as an Invisible EXE task, so the user couldn't interact with the command prompt and eventually close the window (I know, I know, it makes the whole echoes stupid, but it was for testing purposes).for that I used BAT to EXE converter 2.3.1, you can put everything to work on the background and it will work very nicelly. if you want to show progress to users just write START Echo "info" and replace the info with whatever you want, it will open another prompt and show the info you need.
Remember, Wmic commands sometimes take up to 20 seconds to execute since it's querying the conputer's system, so it might look like it's doing nothing at first but it will run! ;)
Good luck :)
We needed a batch file to remove a program and we couldn't use programmatic access to the registry.
For us, we needed to remove a custom MSI with a unique name. This only works for installers that use msi or integrate such that their cached installer is placed in the Package_Cache folder. It also requires a unique, known name for the msi or exe. That said, it is useful for those cases.
dir/s/b/x "c:\programdata\packag~1\your-installer.msi" > removeIt.bat
set /p RemoveIt=< removeIt.bat
echo ^"%RemoveIt%^" /quiet /uninstall > removeIt.bat
removeIt.bat
This works by writing all paths for 'your-installer.msi' to the new file 'removeIt.bat'
It then assigns the first line of that bat file to the variable 'RemoveIt'
Next, it creates a new 'removeIt.bat' that contains the path/name of the .msi to remove along with the needed switches to do so.
Finally, it runs the batch file which executes the command to uninstall the msi. This could be done with an .exe as well.
You will probably want to place the 'removeIt.bat' file into a known writable location, for us that was the temp folder.

Pausing a batch file when double-clicked but not when run from a console window?

Is there a way for a batch file (in this case, running on Windows XP) to determine whether it was launched from a command line (i.e. inside a console window) or launched via the shell (e.g. by double-clicking)?
I have a script which I'd like to have pause at certain points when run via the shell, but not when run at a command line. I've seen a similar question on SO, but am unable to use the same solution for two reasons: first, whether or not it pauses needs to be dependent on multiple factors, only one of which is whether it was double-clicked. Second, I'll be distributing this script to others on my team and I can't realistically ask all of them to make registry changes which will affect all scripts.
Is this possible?
Found one :-) – After desperately thinking of what cmd might do when run interactively but not when launching a batch file directly ... I finally found one.
The pseudo-variable %cmdcmdline% contains the command line that was used to launch cmd. In case cmd was started normally this contains something akin to the following:
"C:\Windows\System32\cmd.exe"
However, when launching a batch file it looks like this:
cmd /c ""C:\Users\Me\test.cmd" "
Small demo:
#echo off
for %%x in (%cmdcmdline%) do if /i "%%~x"=="/c" set DOUBLECLICKED=1
if defined DOUBLECLICKED pause
This way of checking might not be the most robust, though, but /c should only be present as an argument if a batch file was launched directly.
Tested here on Windows 7 x64. It may or may not work, break, do something weird, eat children (might be a good thing) or bite you in the nose.
A consolidated answer, derived from much of the information found on this page (and some other stack overflow pages with similar questions). This one does not rely on detecting /c, but actually checks for the name of the script in the command line. As a result this solution will not pause if you double-clicked on another batch and then called this one; you had to double-click on this particular batch file.
:pauseIfDoubleClicked
setlocal enabledelayedexpansion
set testl=%cmdcmdline:"=%
set testr=!testl:%~nx0=!
if not "%testl%" == "%testr%" pause
The variable "testl" gets the full line of the cmd processor call, stripping out all of the pesky double quotes.
The variable "testr" takes "testl" and further strips outs the name of the current batch file name if present (which it will be if the batch file was invoked with a double-click).
The if statement sees if "testl" and "testr" are different. If yes, batch was double-clicked, so pause; if no, batch was typed in on command line (or called from another batch file), go on.
Edit: The same can be done in a single line:
echo %cmdcmdline% | findstr /i /c:"%~nx0" && set standalone=1
In plain English, this
pipes the value of %cmdcmdline% to findstr, which then searches for the current script name
%0 contains the current script name, of course only if shift has not been called beforehand
%~nx0 extracts file name and extension from %0
>NUL 2>&1 mutes findstr by redirecting any output to NUL
findstr sets a non-zero errorlevel if it can't find the substring in question
&& only executes if the preceding command returned without error
as a consequence, standalone will not be defined if the script was started from the command line
Later in the script we can do:
if defined standalone pause
One approach might be to create an autoexec.nt file in the root of c:\ that looks something like:
#set nested=%nested%Z
In your batch file, check if %nested% is "Z" - if it is "Z" then you've been double-clicked, so pause. If it's not "Z" - its going to be "ZZ" or "ZZZ" etc as CMD inherits the environment block of the parent process.
-Oisin
A little more information...
I start with a batch-file (test.cmd) that contains:
#echo %cmdcmdline%
If I double-click the "test.cmd" batch-file from within Windows Explorer, the display of echo %cmdcmdline% is:
cmd /c ""D:\Path\test.cmd" "
When executing the "test.cmd" batch-file from within a Command Prompt window, the display of
echo %cmdcmdline% depends on how the command window was started...
If I start "cmd.exe" by clicking the "Start-Orb" and "Command Prompt" or if I click "Start-Orb" and execute "cmd.exe" from the search/run box. Then I execute the "test.cmd" batch-file, the display of echo %cmdcmdline% is:
"C:\Windows\system32\cmd.exe"
Also, for me, if I click "Command Prompt" from the desktop shortcut, then execute the "test.cmd" batch-file, the display of echo %cmdcmdline% is also:
"C:\Windows\system32\cmd.exe"
But, if I "Right-Click" inside a Windows Explorer window and select "Open Command Prompt Here", then execute the "test.cmd" batch-file, the display of echo %cmdcmdline% is:
"C:\Windows\System32\cmd.exe" /k ver
So, just be careful, if you start "cmd.exe" from a shortcut that contains a "/c" in the "Target" field (unlikely), then the test in the previous example will fail to test this case properly.

Resources